Repository navigation
Merged
Conversation
…??` over an Option (#2386) Root cause: ComptimeEval's method dispatch (src/ComptimeEval.w, the receiver switch before "method '…' is not comptime-evaluable yet") had no CV_ARRAY case. D117's array/slice first/last/rest are compiler-declared, with no std body for the evaluator to run, so `comptime A.first()` was refused. The issue's own spelling, `A.first() ?? &-1`, also met the evaluator's binary operator with no OP_DEFAULT case ("operator requires integer comptime values"). eval_array_view_method_call: first/last give Some(the element's own arena slot) or None; rest is the tail's (start + 1, count - 1) view. A const is evaluated before Sema types its expressions, so the Option[&T] comes from the element's own type when the call node has none, and an untyped array's tail is typed from its element, so an empty tail still knows what first() yields. eval_binary evaluates `opt ?? fallback` lazily: the payload of a Some, else the fallback. Test: test/behavior/behav_2386_comptime_array_first_last_rest.w (expect "1 3 2 3 -1"). The installed compiler refuses `first`.
?? over an Option (#2386)
ehartford
marked this pull request as ready for review
October 25, 2026 21:59
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.
Root cause: ComptimeEval's method dispatch (src/ComptimeEval.w, the receiver
switch before "method '…' is not comptime-evaluable yet") had no CV_ARRAY
case. D117's array/slice first/last/rest are compiler-declared, with no std
body for the evaluator to run, so
comptime A.first()was refused. Theissue's own spelling,
A.first() ?? &-1, also met the evaluator's binaryoperator with no OP_DEFAULT case ("operator requires integer comptime
values").
eval_array_view_method_call: first/last give Some(the element's own arena
slot) or None; rest is the tail's (start + 1, count - 1) view. A const is
evaluated before Sema types its expressions, so the Option[&T] comes from
the element's own type when the call node has none, and an untyped array's
tail is typed from its element, so an empty tail still knows what first()
yields. eval_binary evaluates
opt ?? fallbacklazily: the payload of aSome, else the fallback.
Test: test/behavior/behav_2386_comptime_array_first_last_rest.w
(expect "1 3 2 3 -1"). The installed compiler refuses
first.Closes #2386