Skip to content

bug: W2011 warning for unused named return values not implemented #1556

@SchoolyB

Description

@SchoolyB

Description

The compiler does not emit W2011 when a function declares named return values in its signature but the function body never declares variables matching those names. Named return values serve as documentation — if the programmer names them but then never creates corresponding variables, the names are misleading.

Note: E3080 already rejects return statements that don't return the exact named variables. W2011 catches the earlier case where the named return identifiers have no corresponding variable declarations in the function body at all.

Repro

do divide(a int, b int) -> (quotient int, remainder int) {
    mut q int = a / b
    mut r int = a % b
    return q, r
}

do main() {
    mut q, r = divide(10, 3)
    println(q)
    println(r)
}

Expected: Compiler emits W2011 on the function definition — quotient and remainder are declared as named return values but no variables with those names exist in the function body.

Actual: No warning emitted (E3080 fires on the return statement, but the signature mismatch goes undiagnosed).

Where to look

ezc/src/typechecker/typechecker.c — after check_block() processes the function body (around line 6062). Iterate tc->current_return_names and check whether each name exists as a symbol in the function scope. If not, emit W2011 on the function signature.

Register W2011 in ezc/src/util/error_codes.h if not already present, and run ./scripts/generate_errors.sh.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions