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
#[TypeDef] repr is not enforced: an out-of-range value is silently truncated in a narrow slot #110
A #[TypeDef(repr: 'i8')] value is a full 64-bit int everywhere except in a narrow slot, and nothing checks its range, so the same value means different things depending on where it is stored:
Arithmetic in a method (new I8($a->value + $b->value)) silently changes meaning the same way once the result is stored.
Proposal
Enforce repr once, where the value is created: every new C(…) of a narrow TypeDef checks the value its constructor or normaliser produced.
Out of range is a ValueError("Value 300 is out of range for I8 (-128..127)") — never a silent wrap. Wrap-around is written out by the programmer ((($x + 128) & 0xFF) - 128).
f32 rounds to binary32 at creation, so a register and a slot hold the same number; a finite value beyond binary32's range is the ValueError, infinities and NaN pass.
i64, u64, f64 and a TypeDef with no repr are unchanged.
Acceptance criteria
new I8(300), new I8(-129) and an out-of-range normaliser result throw ValueError with the class name and range.
An in-range value reads the same from a local, a property slot and a typed-array element.
f32 values are binary32-rounded at creation; 1e39 throws; INF and NAN pass.
Activity