Skip to content

Commit 7ed55f7

Browse files
committed
Emit a proper error when trying to return a value from a void function, fixes #142
1 parent 02e0a91 commit 7ed55f7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

dist/assemblyscript.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/assemblyscript.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,15 @@ export class Compiler extends DiagnosticEmitter {
17551755

17561756
if (statement.value) {
17571757
let returnType = flow.returnType;
1758+
if (returnType == Type.void) {
1759+
this.compileExpressionRetainType(statement.value, returnType, WrapMode.NONE);
1760+
this.error(
1761+
DiagnosticCode.Type_0_is_not_assignable_to_type_1,
1762+
statement.value.range, this.currentType.toString(), returnType.toString()
1763+
);
1764+
this.currentType = Type.void;
1765+
return module.createUnreachable();
1766+
}
17581767
expr = this.compileExpression(
17591768
statement.value,
17601769
returnType,

0 commit comments

Comments
 (0)