Repository navigation
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 intoSep 24, 2026
Merged
Conversation
…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.
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
f(pair())withf(t: (i64, i64))andpair -> (i32, i32)passed Semaand failed in codegen: "wrong argument type actual=struct{i32,i32}
expected=struct{i64,i64}". A return, an assignment and a
Resultreturnof 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 anowned 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 pinvalid MIR -> errorreturn 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_fixturescheck 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 letthem 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).