diff --git a/src/compiler.ts b/src/compiler.ts index e1f38fb4..763a9793 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1948,12 +1948,12 @@ export class Compiler extends DiagnosticEmitter { var module = this.module; var expr: ExpressionRef = 0; var flow = this.currentFlow; + var returnType = flow.returnType; // Remember that this flow returns flow.set(FlowFlags.RETURNS); if (statement.value) { - let returnType = flow.returnType; if (returnType == Type.void) { this.compileExpressionRetainType(statement.value, returnType, WrapMode.NONE); this.error( @@ -1974,6 +1974,13 @@ export class Compiler extends DiagnosticEmitter { // Remember whether returning a properly wrapped value if (!flow.canOverflow(expr, returnType)) flow.set(FlowFlags.RETURNS_WRAPPED); + + } else if (returnType != Type.void) { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + statement.range, "void", returnType.toString() + ); + expr = module.createUnreachable(); } // If the last statement anyway, make it the block's return value