Skip to content

Commit

Permalink
TBD-204: Empty interfaces break the parser (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
fumer-fubotv authored Feb 28, 2024
1 parent f6f4060 commit deb721b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ export class Parser {
let body = [] as Statement[];
while (this.checkAny(TokenKind.Comment, TokenKind.Identifier, TokenKind.At, ...AllowedProperties)) {
try {
//break out of this loop if we encountered the `EndInterface` token not followed by `as`
if (this.check(TokenKind.EndInterface) && !this.checkNext(TokenKind.As)) {
break;
}

let decl: Statement;

//collect leading annotations
Expand Down Expand Up @@ -528,10 +533,6 @@ export class Parser {

//ensure statement separator
this.consumeStatementSeparators();
//break out of this loop if we encountered the `EndInterface` token not followed by `as`
if (this.check(TokenKind.EndInterface) && !this.checkNext(TokenKind.As)) {
break;
}
}

//consume the final `end interface` token
Expand Down
9 changes: 9 additions & 0 deletions src/parser/tests/statement/InterfaceStatement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ describe('InterfaceStatement', () => {
end interface
`, undefined, undefined, undefined, true);
});

it('supports empty interfaces', () => {
const file = program.setFile('source/main.bs', `
interface SomeInterface
end interface
`);
program.validate();
expectZeroDiagnostics(file);
});
});

0 comments on commit deb721b

Please sign in to comment.