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

Fail early when a top level statement fails to resolve #1202

Closed
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
16 changes: 10 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ export class Compiler extends DiagnosticEmitter {
var flow = startFunction.flow;
this.currentFlow = flow;
for (let statements = file.source.statements, i = 0, k = statements.length; i < k; ++i) {
this.compileTopLevelStatement(statements[i], startFunctionBody);
if(!this.compileTopLevelStatement(statements[i], startFunctionBody)) return;
}
this.finishAutoreleases(flow, startFunctionBody);
// no need to insert unreachable since last statement should have done that
Expand Down Expand Up @@ -1835,7 +1835,7 @@ export class Compiler extends DiagnosticEmitter {
// === Statements ===============================================================================

/** Compiles a top level statement (incl. function declarations etc.) to the specified body. */
compileTopLevelStatement(statement: Statement, body: ExpressionRef[]): void {
compileTopLevelStatement(statement: Statement, body: ExpressionRef[]): bool {
switch (statement.kind) {
case NodeKind.CLASSDECLARATION: {
let memberStatements = (<ClassDeclaration>statement).members;
Expand All @@ -1861,7 +1861,7 @@ export class Compiler extends DiagnosticEmitter {
this.currentParent = element;
let memberStatements = declaration.members;
for (let i = 0, k = memberStatements.length; i < k; ++i) {
this.compileTopLevelStatement(memberStatements[i], body);
if(!this.compileTopLevelStatement(memberStatements[i], body)) return false;
}
this.currentParent = previousParent;
}
Expand All @@ -1876,15 +1876,17 @@ export class Compiler extends DiagnosticEmitter {
if (
!element.is(CommonFlags.AMBIENT) && // delay imports
!element.hasDecorator(DecoratorFlags.LAZY)
) this.compileGlobal(<Global>element);
) {
if(!this.compileGlobal(<Global>element)) return false;
}
}
}
break;
}
case NodeKind.FIELDDECLARATION: {
let element = this.program.getElementByDeclaration(<FieldDeclaration>statement);
if (element !== null && element.kind == ElementKind.GLOBAL) { // static
if (!element.hasDecorator(DecoratorFlags.LAZY)) this.compileGlobal(<Global>element);
if (!element.hasDecorator(DecoratorFlags.LAZY)) return this.compileGlobal(<Global>element);
}
break;
}
Expand All @@ -1897,7 +1899,7 @@ export class Compiler extends DiagnosticEmitter {
break;
}
case NodeKind.EXPORTDEFAULT: {
this.compileTopLevelStatement((<ExportDefaultStatement>statement).declaration, body);
return this.compileTopLevelStatement((<ExportDefaultStatement>statement).declaration, body);
break;
}
case NodeKind.IMPORT: {
Expand All @@ -1916,6 +1918,8 @@ export class Compiler extends DiagnosticEmitter {
break;
}
}

return true;
}

/** Compiles a statement. */
Expand Down