Summary
Stmt::Return handling in the type checker never checks that the returned expression's type matches the function's declared return type. A function can declare -> i32 and return a String with no compile error.
Location
crates/compiler/src/type_checker.rs:1146-1150:
Stmt::Return { value, .. } => {
if let Some(expr) = value {
self.check_expr(expr);
// TODO: Check return type matches function signature
} else {
// Return without value - should be void function
}
}
Reproduction
fn bad_return() -> i32 {
return "not an int";
}
Compiles successfully with no type error. Verified against current main (v0.0.5, gdext 0.5.4) via a standalone repro using ferrisscript_compiler::compile().
Expected
Should raise a type-mismatch error (likely fits under the existing E2xx type-error range, e.g. reusing/extending E200 "Type Mismatch") when the return expression's type doesn't match the function's declared return type, and similarly should error if a non-void function has a bare return; (no value) or falls through without returning.
Why it matters
This is a silent soundness gap in a compiler whose core value proposition is "if it compiles, it works" (per README). Found during a broader technical-debt review of the v0.0.5 release.
Summary
Stmt::Returnhandling in the type checker never checks that the returned expression's type matches the function's declared return type. A function can declare-> i32and return aStringwith no compile error.Location
crates/compiler/src/type_checker.rs:1146-1150:Reproduction
Compiles successfully with no type error. Verified against current
main(v0.0.5, gdext 0.5.4) via a standalone repro usingferrisscript_compiler::compile().Expected
Should raise a type-mismatch error (likely fits under the existing E2xx type-error range, e.g. reusing/extending E200 "Type Mismatch") when the return expression's type doesn't match the function's declared return type, and similarly should error if a non-void function has a bare
return;(no value) or falls through without returning.Why it matters
This is a silent soundness gap in a compiler whose core value proposition is "if it compiles, it works" (per README). Found during a broader technical-debt review of the v0.0.5 release.