You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sema: struct-literal fields skip value-type checking entirely (str into i32 field accepted) #896
Found while fixing #886. The struct-literal field loop's only type-mismatch
rejection is gated on the VALUE being a &T view; a non-ref wrong-typed value
is never checked. The union case is now rejected (§16.4, #886), but the
general hole remains:
type P { n: i32, s: str }
fn main:
let a = P { n: "hello", s: "ok" } // ACCEPTED — zero diagnostics
print(f"{a.n}") // garbage at codegen
Also accepted: type Q { n: i32 }; P2 { q: 7 } (scalar into a plain
struct-typed field) — which happens to "work" by accidental positional
flattening, and is blessed nowhere in the spec (checked: §struct-literal
forms defines named/positional/block/update/shorthand only; no scalar
wrapping).
The binding/call/assignment paths all reject these via types_compatible +
arithmetic_result_type; the field loop needs the same predicate. Held out
of the #886 commit because the blast radius is different: generic fields
(field types may be unresolved params after the rebind-to-BASE step) need
a careful gate, and any in-tree reliance on the accidental acceptance
surfaces as new errors — wants its own battery.
Repro of the sema hole: see above; the mismatch check to mirror is
SemaCheck's binding path ("type mismatch in binding": types_compatible ==
0 && no contextual-copy && arithmetic_result_type == 0).
Fixed: the field loop's mismatch rejection is now the ordinary structural predicate (types_compatible) instead of firing only when the VALUE was a &T view. P { n: "oops", s: 42 } errors on both fields with the field name and both types; carve-outs are explicit — union fields keep their §16.4 message, dyn-object fields coerce, contextual-Copy adjustments stand, and integer literals still initialize pointer fields (the stdlib's own Vec{ ptr: 0 } null idiom, which the first full-corpus run caught). The scalar-into-struct-field accidental flattening from the report is likewise rejected by the general predicate. Full :test green, evidence recorded.
Activity
ehartford commentedon Sep 1, 2026
Fixed: the field loop's mismatch rejection is now the ordinary structural predicate (types_compatible) instead of firing only when the VALUE was a &T view.
P { n: "oops", s: 42 }errors on both fields with the field name and both types; carve-outs are explicit — union fields keep their §16.4 message, dyn-object fields coerce, contextual-Copy adjustments stand, and integer literals still initialize pointer fields (the stdlib's ownVec{ ptr: 0 }null idiom, which the first full-corpus run caught). The scalar-into-struct-field accidental flattening from the report is likewise rejected by the general predicate. Full :test green, evidence recorded.sema: struct-literal fields reject any incompatible value, not only v…
sema: raw-pointer struct-literal fields accept any raw pointer (#896 …