mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Emit proper diagnostic when returning void from a function with a return value, fixes #475
This commit is contained in:
parent
fadfe6e421
commit
e623786b42
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user