Skip to content

D183 (#2522): an integer at a narrower or other-signed demand converts with a range check (§4.2.6) - #2989

Merged
ehartford merged 1 commit into
mainfrom
d183-checked-narrowing
Nov 2, 2026
Merged

ehartford merged 1 commit into
mainfrom
d183-checked-narrowing

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Item 2 of bridge-the-impl-gap.md, ruled by Eric 2026-11-02 (D183). Sema admits the narrowing and records it; MIR emits the range check (D71's shape: compare in the source type, panic edge, cast on the pass path); a lint warns at the use naming the narrow declaration (pointing the span at the declaration itself is a follow-up). Nineteen err_1803 fixtures that pinned the old refusal retire; four new behavior fixtures; conformance rows D183 and D184 flip. The .len() as i32 sweep is a separate PR. Battery to follow.

…demanded converts with a range check (§4.2.6)

Sema admits the narrowing at every demand (a binding's annotation, an
argument, a return, a field, an element, a payload) and records the node
with the demanded type (checked_narrowings); the refusal "implicit integer
narrowing or sign change ... use an explicit `as` cast" is gone. The lint
the ruling asks for warns that the value narrows with a range check and
names the declaration it flows into (widen it, or write `as` for the
wrap). MIR converts the recorded node with the D71 shape: the
destination's bounds compared in the source's type, a panic edge
("integer does not fit `i32` (§4.2.6)", exit 134) and the cast on the
pass path; a check the source's own range makes redundant is not
emitted, and a 128-bit destination checks only its sign bound. Mixed
signedness in arithmetic, a float where an integer is demanded and the
wrapping operators keep their refusals.

A comptime value out of range was already a compile error (an integer
literal that does not fit, overflow in comptime).

Fixtures: behav_d183_checked_narrowing (every demand position, in range),
behav_d183_narrowing_out_of_range_panics, behav_d183_sign_change_out_of_
range_panics, behav_d183_narrowing_lints_the_declaration; the nineteen
err_1803 fixtures that pinned the refusal retire, the four that pin the
remaining refusals stay. Conformance rows D183 and D184 flip to
implemented. The `.len() as i32` sweep follows separately.
@ehartford
ehartford force-pushed the d183-checked-narrowing branch from aad6117 to 515734e Compare November 2, 2026 22:06
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on 515734e (out/battery/status.txt: rc= green). From the first red: six more fixtures that pinned the old refusal retired or became behavior tests (the D156 seam note is now a warning on the build, pinned with expect-build-stderr); the two discarded-result bindings the census counted are gone; the native-compile-error lane passes 1851 files.

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