-
Notifications
You must be signed in to change notification settings - Fork 208
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
Do we need a null assertion operator, and if so what is the syntax? #196
Comments
My preferences are:
I don't think we need any special case support for int? n;
expectsInt(n!);
someJson["key"]!["subkey"];
var value = someMap["key"]!; |
I think to make this work out in general, we either need the |
I think we're converging on a clear |
+1 on Syntactically, I think we will need a special case for |
Agree on |
+1 |
We can't deal with this via precedence? In any case, however we handle it, we'll probably need to be sure we can handle |
There will be an operator, and the syntax is |
In some situations, program invariants may establish that a variable is non-null in a way that cannot be made apparent to the type system. Kotlin, Swift, and Typescript all have some form of null assertion operator to handle this.
The postfix
!
operator has been proposed for this, since it is a familiar idiom from other languages (see below).This issue is for discussion of the operator, and possible alternative syntax. cc @Hixie @munificent @lrhn @eernstg
For reference, the operator in other languages:
Kotlin has the
!!
operator, which throws if the argument is nullSwift has both a
!
(force unwrap) operator (throws if nil), and also an implicitly unwrapped type which causes an implicit unwrap on each use.Typescript has a purely static null assertion operator.
The text was updated successfully, but these errors were encountered: