Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty interfaces break the parser #1082

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});