-
Notifications
You must be signed in to change notification settings - Fork 424
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
Nilability ergonomics: optional chaining #17577
Comments
Sounds good to me.
I'd expect it would work with e.g. |
Right. Then, what if there is no var x = 5;
var y = x?.someMethodOnInts(); Should If so, should |
I'd lean towards having Taken back to classes, let us suppose we have class types C and D. It would be good to know what approach Swift takes for these cases. Can you investigate? |
Optional chaining In Swift states that the result of an This is necessary -- because So, should we disallow Alas, the Chapel-Swift analogy does not go very far. In particular, Chapel allows postfix- With that in mind, I propose the following rules:
|
Nilability ergonomics / convenience features have been proposed in #12614 and forked off into #16931. The first of them is the topic of #13639, already implemented.
This issue requests the second convenience feature that is akin to Swift's Optional Chaining
This feature is a shorthand for this kind of conditional expression:
that uses this syntax, which is inspired by Swift:
This syntax probably entails defining a new postfix operator
?.
to differentiate from the the postfix?
, which is allowed only on types.The semantics is clear when
x
is a class andsomeMethod()
returns a class, nilable or non-nilable.A design question is: should we allow it for other types? For non-classes, the semantics could be:
A consideration here is whether the user can tell, from the result of the expression, whether the
then
orelse
branch was taken. It is possible in the case wherex
is a class andsomeMethod()
returns a non-nilable class, otherwise it is not possible to tell.The text was updated successfully, but these errors were encountered: