Emit a proper error when trying to return a value from a void function, fixes #142

This commit is contained in:
dcodeIO 2018-06-21 03:47:05 +02:00
parent 02e0a91070
commit 7ed55f7ea6
3 changed files with 11 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1755,6 +1755,15 @@ export class Compiler extends DiagnosticEmitter {
if (statement.value) {
let returnType = flow.returnType;
if (returnType == Type.void) {
this.compileExpressionRetainType(statement.value, returnType, WrapMode.NONE);
this.error(
DiagnosticCode.Type_0_is_not_assignable_to_type_1,
statement.value.range, this.currentType.toString(), returnType.toString()
);
this.currentType = Type.void;
return module.createUnreachable();
}
expr = this.compileExpression(
statement.value,
returnType,