Skip to content
This repository was archived by the owner on Jul 21, 2026. It is now read-only.
This repository was archived by the owner on Jul 21, 2026. It is now read-only.

Type checker doesn't validate return type matches function signature #66

Description

@dev-parkins

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-HighHigh priority tasks that should be addressed soonbugSomething isn't workingcompilerRelated to compiler crate (lexer, parser, type checker)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions