Repository navigation
Sema: Type.from_int(n) is an Option[Type] (#1453) - #1541
Merged
Merged
Conversation
ehartford
force-pushed
the
fix-1453-from-int-type
branch
from
September 23, 2026 20:17
02585ee to
540a985
Compare
`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
force-pushed
the
fix-1453-from-int-type
branch
from
September 23, 2026 20:43
540a985 to
dd9a730
Compare
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: |
ehartford
marked this pull request as ready for review
September 23, 2026 21:34
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]>
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.
let c: Option[Color] = Color.from_int(2)was "type mismatch inbinding": 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 alreadybuilds the value as
{ tag, repr }, which is the enum's Option (apayloadless 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 inferredbinding 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).