Skip to content

Commit

Permalink
Type casts are not allowed in BrightScript (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
markwpearce authored Jul 28, 2023
1 parent 81e6391 commit 4e78f81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/parser/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,20 @@ describe('parser', () => {
});

describe('type casts', () => {

it('is not allowed in brightscript mode', () => {
let parser = parse(`
sub main(node as dynamic)
print lcase((node as string))
end sub
`, ParseMode.BrightScript);
expect(
parser.diagnostics[0]?.message
).to.equal(
DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('type cast').message
);
});

it('allows type casts after function calls', () => {
let { statements, diagnostics } = parse(`
sub main()
Expand Down
1 change: 1 addition & 0 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,7 @@ export class Parser {
if (findTypeCast) {
do {
if (this.check(TokenKind.As)) {
this.warnIfNotBrighterScriptMode('type cast');
// Check if this expression is wrapped in any type casts
// allows for multiple casts:
// myVal = foo() as dynamic as string
Expand Down

0 comments on commit 4e78f81

Please sign in to comment.