Skip to content

Aggregate element width mismatch at a call argument reaches codegen (wrong argument type) instead of a Sema error #1368

Closed

Description

@ehartford

Sema accepts a fixed-type aggregate whose element representation differs from the expected parameter type, and codegen rejects it. types_compatible recurses into tuple, array and generic-instance elements with the scalar relation, where any int matches any int and int matches float. No conversion reshapes an aggregate value.

Repro (a stage1 built from origin/main 5fd93bc):

fn f(t: (i64, i64)) -> i64: t.0 + t.1
fn pair -> (i32, i32): (3, 4)
fn main:
    print(f"{f(pair())}")

Actual: error: wrong argument type actual=struct{i32,i32} expected=struct{i64,i64} fn=main / error: code generation failed.
Expected: a Sema type error at the argument.

The binding sites are fixed in #1354's PR. check_binding_annotation / aggregate_repr_differs (src/SemaCheck.w) reject let t: (i64, i64) = pair() and let (a, b): (i64, i64) = pair(), where they used to fail as invalid MIR. Call arguments, returns and assignments still use the loose relation. The fix is to apply the same element-representation rule at those sites. Constructors lowered against the expected type ((1, x), Some(x)) come back typed as expected and are unaffected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions