Description
A function declared with a single return type can return multiple comma-separated values without the typechecker catching it. The codegen then emits a multi-return struct (EzMulti_foo) that was never typedef'd, causing a C compilation crash.
Reproduction
do foo() -> int {
return 1, 2
}
do main() {
println(foo())
}
Expected: Compile error — foo declares a single int return but returns 2 values
Actual: Typechecker passes, C compilation fails:
error: use of undeclared identifier 'EzMulti_foo'
{ EzMulti_foo _ret = (EzMulti_foo){1, 2}; ez_exit_func(); return _ret; }
^
Root Cause
The typechecker does not validate that the number of values in a return statement matches the number of declared return types. When a function is declared as -> int (single return), returning 1, 2 should be rejected. The codegen assumes the typechecker has validated this and emits a multi-return struct path for the comma-separated values, but no such struct was defined since the function signature only declares one return value.
Fix
In the typechecker's return statement handler, count the number of comma-separated return values and compare against the function's declared return count. If they don't match, emit an error like:
E3XXX: function 'foo' returns 1 value but return statement has 2 values
Description
A function declared with a single return type can return multiple comma-separated values without the typechecker catching it. The codegen then emits a multi-return struct (
EzMulti_foo) that was never typedef'd, causing a C compilation crash.Reproduction
Expected: Compile error —
foodeclares a singleintreturn but returns 2 valuesActual: Typechecker passes, C compilation fails:
Root Cause
The typechecker does not validate that the number of values in a
returnstatement matches the number of declared return types. When a function is declared as-> int(single return), returning1, 2should be rejected. The codegen assumes the typechecker has validated this and emits a multi-return struct path for the comma-separated values, but no such struct was defined since the function signature only declares one return value.Fix
In the typechecker's return statement handler, count the number of comma-separated return values and compare against the function's declared return count. If they don't match, emit an error like: