-
Notifications
You must be signed in to change notification settings - Fork 200
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
Proposal: align front end behavior with analyzer for if-null expressions in context dynamic
.
#3650
Comments
No objection. Although I do want to question why My guess is that it's because Could we choose to go the other way, and make both the analyzer do what the front end does instead? What would the cost be? Someone would get (Could we go further and respect |
No objections here, either. Seems to be the consistent resolution of the discrepancy. |
SGTM |
…lyzer. Fixes dart-lang/language#3650. Fixes #55436. Bug: dart-lang/language#3650 Change-Id: I30b39221c85713aab10f2edc35625f38e34cae5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362100 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
Completed via dart-lang/sdk@5b020f2. |
Background: I'm trying to update the expression inference rules in inference.md to match what was implemented, so that we can have a rigorous specification of the
inference-update-3
logic I landed in https://dart-review.googlesource.com/c/sdk/+/353440. In the process I've discovered a subtle difference between the analyzer and front end type inference of if-null expressions. This issue addresses that difference.In the analyzer, type inferring an expression in a context
dynamic
is always considered equivalent to type inferring it in a context_
. This is because the analyzer uses the methodTypeAnalyzer.analyzeExpression
whenever it supplies a context when type inferring an expression, andTypeAnalyzer.analyzeExpression
changes a context ofdynamic
to a context of_
.The front end also has logic that changes a context of
dynamic
to a context of_
, but this logic isn't used for all expression types; it is only used for generic invocations and expressions appearing inside pattern constructs (such as the expressions inside a switch expression). I believe there are only two circumstances in which the difference is observable: when inferring anawait
expression and when inferring an if-null expression. This issue is about the observable difference when inferring an if-null expression.When inferring an if-null expression
e1 ?? e2
in a context ofdynamic
, the front end analyzes bothe1
ande2
with a context ofdynamic
. Whereas the analyzer analyzese1
with a context of_
, ande2
with a context ofT1
, whereT1
is the static type ofe1
.I propose to base my update of the expression inference rules in inference.md on the analyzer's behavior in this corner case, and to change the front end's behavior to match the analyzer's.
This change could in principle cause the front end to reject a program that it previously accepted, however such a program would have been rejected by the analyzer, so this should only crop up in workflows where the analyzer is not used (e.g. a user who doesn't use an IDE, and doesn't run the analyzer as part of a continuous integration setup). It's also conceivable that this change could cause a change in the behavior of a compiled program by changing a reified type parameter.
To reduce the risk of causing a suprising customer breakage, I'm happy to validate this change against google3, and to push it through the breaking change process.
@dart-lang/language-team any objections?
The text was updated successfully, but these errors were encountered: