-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nil-safe accessors #124
Comments
Closed
kengorab
added a commit
that referenced
this issue
Jun 8, 2020
Addresses #124 - Add lexing of `?.` operator - Add parsing of `?.` expressions (it creates an `AstNode::Accessor` whose `AccessorNode` has `is_opt_safe: true`).
kengorab
added a commit
that referenced
this issue
Jun 10, 2020
Addresses #124 - Add lexing of `?.` operator - Add parsing of `?.` expressions (it creates an `AstNode::Accessor` whose `AccessorNode` has `is_opt_safe: true`). - Add typechecking of `?.` expressions. `a?.b` will "unwrap" `a` if it's an optional, and then typechecks the field `b` against it, then re-wraps it as an optional; if `a` is _not_ optional, it's effectively the same as `a.b`; a `Token::Dot` is actually emitted instead of `Token::QuestionDot`, so downstream code will actually compile away the unnecessary optional-safeness.
kengorab
added a commit
that referenced
this issue
Jun 10, 2020
Addresses #124 - Add lexing of `?.` operator - Add parsing of `?.` expressions (it creates an `AstNode::Accessor` whose `AccessorNode` has `is_opt_safe: true`). - Add typechecking of `?.` expressions. `a?.b` will "unwrap" `a` if it's an optional, and then typechecks the field `b` against it, then re-wraps it as an optional; if `a` is _not_ optional, it's effectively the same as `a.b`; a `Token::Dot` is actually emitted instead of `Token::QuestionDot`, so downstream code will actually compile away the unnecessary optional-safeness.
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to be able to have a nil-safe accessor operator (
?.
) to access fields on Optional variables. If the variable isNone
, the entire rest of the expression is skipped and the result isNone
; if the value is notNone
, the next expression in the chain is evaluated. For example:There should also be nil-safe accessors for indexing:
which should behave the same way; a
None
value would be chained along if ever present.The text was updated successfully, but these errors were encountered: