-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[NNBD] Strange CFE error for user-defined ~ operator #42379
Comments
It looks like the analyzer gets the syntactic structure wrong. Here's a variant of the example: class C {
C operator ~() {
return this;
}
C e() {
return this;
}
}
main() {
C c = new C();
~(c?.e());
} With this version, nullsafety.dartpad.dev reports 'An expression whose value can be 'null' must be null-checked before it can be dereferenced' from the analyzer on line 13, and the front end still reports 'Operator '~' cannot be called on 'C?' because it is potentially null'. So when the parentheses are added, we get the expected error from both the analyzer and the CFE, but without the parentheses, the message from the analyzer only fits the parsing structure In order for |
The language spec says in The NNBD spec says that I don't understand the statement about |
@scheglov wrote:
Indeed, it does! However, the language specification uses the same approach for a large number of binary operations, which would make constructs like So I find it highly unlikely that we will include the binary operations in null-shorting (and the tools actually don't do that today). So we may also decide to exclude these prefix operators, for consistency. I created dart-lang/language#1081 in order to clarify this question. |
…ix expressions. Bug: #42379 Change-Id: I366702f144a4350bed6b83c5c0936359aeeae2c1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159960 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
The following code produces a warning in analyzer and warning and error in VM
Analyzer output is
Dart VM produces
Dart VM version: 2.9.0-16.0.dev (dev) (Tue Jun 16 10:35:10 2020 +0200) on "windows_x64"
The text was updated successfully, but these errors were encountered: