Repository navigation
feat: test a value's type with x as? T 🔍 - #347
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Making
Anyexplicit (#331) leaves a cast as the only way to get a value out ofAny, and there was no way to test a value's type:x as Tstops the program whenxisn't aT.x as? Tis that test:Some(x), as aT, when the value is aT, andNonewhen it isn't. It has typeOption<T>.as?, which has the precedence ofas(so(x as? Int).is_some()needs its parentheses) and needs a space after it, as?can be part of a name.as: a cast that can never succeed is an error (it would always beNone), and one it can prove needs no check. Unlikeas, it doesn't settle what isn't known about the value: testingxs as? List<Int>leaves an empty list free to hold Strings. A number written there still takes the type:1 as? FloatisSome(1.0).TryCastinstruction converts the value asasdoes, functions included (they get their calls checked), and givesNoneinstead of failing. Its body is out of the VM's main loop, so calls run exactly as before (fib(27)executes the same number of instructions).The manual's casts page has a section on it.
🤖 Generated with Claude Code