Skip to content

Sema: an aggregate whose elements differ in representation is a type error at calls, returns, assignments, fields, payloads and sequence literals, never a codegen failure or a silent misread (#1368) - #1579

Merged
ehartford merged 1 commit into
fix-1389-slice-pattern-vecfrom
fix-1368-aggregate-width-call-args
Sep 24, 2026

Conversation

@ehartford

@ehartford ehartford commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

f(pair()) with f(t: (i64, i64)) and pair -> (i32, i32) passed Sema
and failed in codegen: "wrong argument type actual=struct{i32,i32}
expected=struct{i64,i64}". A return, an assignment and a Result return
of the same shape were invalid MIR ("use rvalue type is incompatible with
assign destination"); a struct field initialized that way COMPILED and
printed 17179869187 for (3, 4): a silent wrong value.

Root cause: types_compatible recurses into tuple, array and generic
instance elements with the scalar relation (Sema.w:7398-7431), where any
int matches any int and int matches float. That widening exists for
scalars, which convert; no conversion reshapes an aggregate value.
#1354 added aggregate_repr_differs for annotated bindings only.

Fix: value_aggregate_repr_differs applies that rule at every value
demand, seeing through one level of & on either side (auto-ref of an
owned value, a materialized Copy view, a view passed along):
call_arg_type_compatible (free calls, methods, callables, Vec.push and
the other builtin methods, enum and Some payloads), return_value_type_
compatible and the explicit-return check (with the Result ok-type case),
both assignment paths, struct literal fields and sequence literal
elements. Literal aggregates written against an expected type are typed
as that type by the existing expected-type paths and are unaffected.

Matrix (stage1 before -> after; "error" is a Sema diagnostic at the site):
call arg pair() -> (i64,i64) codegen failure -> error
&Vec[i32] to &Vec[i64] (auto-ref) compiled, read 4-byte cells as 8 -> error
&(i32,i32) view to (i64,i64) (ctx copy) invalid MIR -> error
return, tail and return p invalid MIR -> error
return into Result[(i64,i64), str] invalid MIR -> error
assignment, field assignment invalid MIR -> error (names both types)
struct field / Vec[i32] into Vec[i64] silent wrong value -> error
Vec[(i64,i64)].push((i32,i32)) compiled -> error
E.V(p), Some(p), [p] against wider silent / invalid MIR -> error
closure arg codegen failure -> error
every literal site with an expected aggregate type -> unchanged, correct
stage1 check src/main.w: ok. examples/ and build/release_uat_fixtures
check identically before and after (raylib needs its header on both).
test sweep (538 tuple/array/call/return/assign/literal/generic tests):
one changed verdict, below; every other failure fails the same way on the
base stage1.

behav_ref_box_generic_receiver (#1443) bound unsuffixed literals through
generic constructors (let b = Box.new(41), Wrap { inner: 40, tag: 2 },
Rc.new(77)) and passed them to &Box[i64]/&Wrap[i64]/&Rc[i64]
parameters. Those bindings are Box[i32] etc.: the loose relation let
them through and the callee read i32 cells as i64, right by alignment
luck. §4.2.1 gives an unsuffixed literal no context in a constructor
bound to a local, so the test now annotates those bindings; the spelling,
not the rule, was wrong. Its let bw: Box[Wrap[i64]] = Box.new(Wrap { inner: 1, ... }) was already a codegen failure on the base
("actual=Wrap__i32 expected=Wrap__i64"), now the Sema error; the test
suffixes the literal. The missing inference there is filed.

Fixtures: err_1368_aggregate_width_{call_arg,return,assignment,
field_silent}, behav_1368_aggregate_literals_take_expected.

Stack #1582, layer 9/11. Draft until the batch battery is green (D56).

…error at calls, returns, assignments, fields, payloads and sequence literals, never a codegen failure or a silent misread (#1368)

`f(pair())` with `f(t: (i64, i64))` and `pair -> (i32, i32)` passed Sema
and failed in codegen: "wrong argument type actual=struct{i32,i32}
expected=struct{i64,i64}". A return, an assignment and a `Result` return
of the same shape were invalid MIR ("use rvalue type is incompatible with
assign destination"); a struct field initialized that way COMPILED and
printed 17179869187 for `(3, 4)`: a silent wrong value.

Root cause: types_compatible recurses into tuple, array and generic
instance elements with the scalar relation (Sema.w:7398-7431), where any
int matches any int and int matches float. That widening exists for
scalars, which convert; no conversion reshapes an aggregate value.
#1354 added aggregate_repr_differs for annotated bindings only.

Fix: value_aggregate_repr_differs applies that rule at every value
demand, seeing through one level of `&` on either side (auto-ref of an
owned value, a materialized Copy view, a view passed along):
call_arg_type_compatible (free calls, methods, callables, Vec.push and
the other builtin methods, enum and Some payloads), return_value_type_
compatible and the explicit-return check (with the Result ok-type case),
both assignment paths, struct literal fields and sequence literal
elements. Literal aggregates written against an expected type are typed
as that type by the existing expected-type paths and are unaffected.

Matrix (stage1 before -> after; "error" is a Sema diagnostic at the site):
  call arg pair() -> (i64,i64)           codegen failure -> error
  &Vec[i32] to &Vec[i64] (auto-ref)      compiled, read 4-byte cells as 8 -> error
  &(i32,i32) view to (i64,i64) (ctx copy) invalid MIR -> error
  return, tail and `return p`           invalid MIR -> error
  return into Result[(i64,i64), str]    invalid MIR -> error
  assignment, field assignment          invalid MIR -> error (names both types)
  struct field / Vec[i32] into Vec[i64] silent wrong value -> error
  Vec[(i64,i64)].push((i32,i32))        compiled -> error
  E.V(p), Some(p), [p] against wider    silent / invalid MIR -> error
  closure arg                            codegen failure -> error
  every literal site with an expected aggregate type -> unchanged, correct
`stage1 check src/main.w`: ok. examples/ and build/release_uat_fixtures
check identically before and after (raylib needs its header on both).
test sweep (538 tuple/array/call/return/assign/literal/generic tests):
one changed verdict, below; every other failure fails the same way on the
base stage1.

behav_ref_box_generic_receiver (#1443) bound unsuffixed literals through
generic constructors (`let b = Box.new(41)`, `Wrap { inner: 40, tag: 2 }`,
`Rc.new(77)`) and passed them to `&Box[i64]`/`&Wrap[i64]`/`&Rc[i64]`
parameters. Those bindings are `Box[i32]` etc.: the loose relation let
them through and the callee read i32 cells as i64, right by alignment
luck. §4.2.1 gives an unsuffixed literal no context in a constructor
bound to a local, so the test now annotates those bindings; the spelling,
not the rule, was wrong. Its `let bw: Box[Wrap[i64]] = Box.new(Wrap
{ inner: 1, ... })` was already a codegen failure on the base
("actual=Wrap__i32 expected=Wrap__i64"), now the Sema error; the test
suffixes the literal. The missing inference there is filed.

Fixtures: err_1368_aggregate_width_{call_arg,return,assignment,
field_silent}, behav_1368_aggregate_literals_take_expected.
@ehartford
ehartford added this pull request to stack #1582 September 23, 2026 21:37
@ehartford ehartford changed the title fix 1368 aggregate width call args Sema: an aggregate whose elements differ in representation is a type error at calls, returns, assignments, fields, payloads and sequence literals, never a codegen failure or a silent misread (#1368) Sep 23, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1582 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 02301f8 + #1571 → … → #1581 (head dca1a8f; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: gh stack merge 1581 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 22:04
@ehartford
ehartford merged commit 161974d into main Sep 24, 2026
@ehartford
ehartford deleted the fix-1368-aggregate-width-call-args branch September 24, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant