Skip to content

Sema: Type.from_int(n) is an Option[Type] (#1453) - #1541

Merged
ehartford merged 1 commit into
fix-1452-disc-rangefrom
fix-1453-from-int-type
Sep 23, 2026
Merged

ehartford merged 1 commit into
fix-1452-disc-rangefrom
fix-1453-from-int-type

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

let c: Option[Color] = Color.from_int(2) was "type mismatch in
binding": from_int was typed Option[i32], the repr's Option, where
§4.4a says Option[Type] (Color.from_int(2) // Some(Color.Green)).
Route: a type error on valid code — the checker's typing of the call.

Evidence. lldb on base stage1, breakpoint on Sema.enum_repr_type: called
from Sema.check_method_call_parts with x1 = 235 (Color), returns x0 = 3
(i32); the from_int branch (SemaCheck.w:22087-22091) wraps that repr in
Option: opt_inner = if repr_ty != 0: repr_ty else: ty_i32.

Fix. The branch types the call Option[<the enum>]. Codegen already
builds the value as { tag, repr }, which is the enum's Option (a
payloadless discriminant enum's value is its repr). An enum with payload
variants keeps the repr's Option: no value exists for a payload
variant's discriminant, and the spec does not say what from_int is
there (#1497).

Matrix (behav_disc_enum_from_int_type): an annotated binding with a
Some(.Green) pattern, a fn returning Option[Color], an inferred
binding under if let, ?? with a Color default, is_some/is_none;
reprs i32, u32 (3000000000), u8 (200, and a miss), i64 (negative), an
inferred-i32 enum; a value matching no discriminant is None. Base: the
fixture does not compile ("return type mismatch" at the fn). Filed while
here: from_int truncates its argument to the repr before comparing, so
Tiny.from_int(456) is Some(Hi = 200) (#1499).


Layer of the enums/discriminants stack (#1455 → #1451 → #1452 → #1453 → #1454 → #1441 → #1442 → #1439 → #1456). Draft until the stack's seed-driven battery is green (D56).

@ehartford
ehartford added this pull request to stack #1547 September 23, 2026 17:06
@ehartford
ehartford force-pushed the fix-1453-from-int-type branch from 02585ee to 540a985 Compare September 23, 2026 20:17
`let c: Option[Color] = Color.from_int(2)` was "type mismatch in
binding": from_int was typed `Option[i32]`, the repr's Option, where
§4.4a says `Option[Type]` (`Color.from_int(2)  // Some(Color.Green)`).
Route: a type error on valid code — the checker's typing of the call.

Evidence. lldb on base stage1, breakpoint on Sema.enum_repr_type: called
from Sema.check_method_call_parts with x1 = 235 (Color), returns x0 = 3
(i32); the from_int branch (SemaCheck.w:22087-22091) wraps that repr in
Option: `opt_inner = if repr_ty != 0: repr_ty else: ty_i32`.

Fix. The branch types the call `Option[<the enum>]`. Codegen already
builds the value as `{ tag, repr }`, which is the enum's Option (a
payloadless discriminant enum's value is its repr). An enum with payload
variants keeps the repr's Option: no value exists for a payload
variant's discriminant, and the spec does not say what from_int is
there (#1497).

Matrix (behav_disc_enum_from_int_type): an annotated binding with a
`Some(.Green)` pattern, a fn returning Option[Color], an inferred
binding under `if let`, `??` with a Color default, is_some/is_none;
reprs i32, u32 (3000000000), u8 (200, and a miss), i64 (negative), an
inferred-i32 enum; a value matching no discriminant is None. Base: the
fixture does not compile ("return type mismatch" at the fn). Filed while
here: from_int truncates its argument to the repr before comparing, so
`Tiny.from_int(456)` is Some(Hi = 200) (#1499).
@ehartford
ehartford force-pushed the fix-1453-from-int-type branch from 540a985 to dd9a730 Compare September 23, 2026 20:43
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1547 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main ce7508c + #1537 → … → #1546 (head bee5c56; every PR head is a tested commit; includes the #1451 same-named-enum fix and the render.w rebase over #1513): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main 02301f8. Merge the stack: gh stack merge 1546 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 21:34
@ehartford
ehartford merged commit 25d49c8 into main Sep 23, 2026
ehartford added a commit that referenced this pull request Sep 24, 2026
…uilt Vec[i32]; main red at stage2 after #1546 + #1581 (#1596)

* MIR: the three switch tables built from Vec[i32] take Vec[i64] — discriminants are i64 end to end (#1541) and the width check (#1368) now rejects the narrowed table; main was red at stage2

* drop-audit: the field_join_view match cell indents its arms under the match — the seed parsed the flush arms by accident; §29.13 (#1391) rejects them

* MirValidationTests: the last switch table built from Vec[i32] takes Vec[i64] — the internals tests compile this file, src/main.w does not

---------

Co-authored-by: Eric Hartford <[email protected]>
@ehartford
ehartford deleted the fix-1453-from-int-type branch September 24, 2026 16:55
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