@@ -6,8 +6,9 @@ import { Parser, ParseMode } from './Parser';
66import type { FunctionStatement , AssignmentStatement , FieldStatement } from './Statement' ;
77import { ClassStatement } from './Statement' ;
88import { NewExpression } from './Expression' ;
9- import { expectDiagnosticsIncludes , expectZeroDiagnostics } from '../testHelpers.spec' ;
9+ import { expectDiagnostics , expectDiagnosticsIncludes , expectZeroDiagnostics } from '../testHelpers.spec' ;
1010import { isClassStatement } from '../astUtils/reflection' ;
11+ import util from '../util' ;
1112
1213describe ( 'parser class' , ( ) => {
1314 it ( 'throws exception when used in brightscript scope' , ( ) => {
@@ -94,6 +95,45 @@ describe('parser class', () => {
9495 expect ( parser . diagnostics [ 0 ] ?. message ) . to . eql ( DiagnosticMessages . cannotUseReservedWordAsIdentifier ( 'throw' ) . message ) ;
9596 } ) ;
9697
98+ it ( 'does not allow function param named "type"' , ( ) => {
99+ const parser = Parser . parse ( `
100+ sub test(type as string)
101+ end sub
102+ ` ) ;
103+
104+ expectDiagnostics ( parser , [ {
105+ ...DiagnosticMessages . cannotUseReservedWordAsIdentifier ( 'type' ) ,
106+ range : util . createRange ( 1 , 21 , 1 , 25 )
107+ } ] ) ;
108+ } ) ;
109+
110+ it ( 'does not allow class method named "type"' , ( ) => {
111+ const parser = Parser . parse ( `
112+ class Person
113+ sub test(type as string)
114+ end sub
115+ end class
116+ ` , { mode : ParseMode . BrighterScript } ) ;
117+
118+ expectDiagnostics ( parser , [ {
119+ ...DiagnosticMessages . cannotUseReservedWordAsIdentifier ( 'type' ) ,
120+ range : util . createRange ( 2 , 25 , 2 , 29 )
121+ } ] ) ;
122+ } ) ;
123+
124+ it ( 'does not allow interface method named "type"' , ( ) => {
125+ const parser = Parser . parse ( `
126+ interface Person
127+ sub test(type as string)
128+ end interface
129+ ` , { mode : ParseMode . BrighterScript } ) ;
130+
131+ expectDiagnostics ( parser , [ {
132+ ...DiagnosticMessages . cannotUseReservedWordAsIdentifier ( 'type' ) ,
133+ range : util . createRange ( 2 , 25 , 2 , 29 )
134+ } ] ) ;
135+ } ) ;
136+
97137 it ( 'supports the try/catch keywords in various places' , ( ) => {
98138 const parser = Parser . parse ( `
99139 sub main()
0 commit comments