Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2217693003: fix #26552, improve null coalescing inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index afa7ccec98ee9c48746663cc1c1a9893c0b0b541..4a70c667c78425be69ed028fa4618aa25b3be919 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -4915,6 +4915,8 @@ class InferenceContext {
* inference.
*/
static void setType(AstNode node, DartType type) {
+ // TODO(jmesserly): this sets the type even when it's dynamic.
+ // Can we skip that?
node?.setProperty(_typeProperty, type);
}
@@ -6062,9 +6064,18 @@ class ResolverVisitor extends ScopedVisitor {
// of the binary operator for other cases.
if (operatorType == TokenType.QUESTION_QUESTION) {
InferenceContext.setTypeFromNode(leftOperand, node);
- InferenceContext.setTypeFromNode(rightOperand, node);
}
leftOperand?.accept(this);
+ if (operatorType == TokenType.QUESTION_QUESTION) {
+ // Set the right side, either from the context, or using the information
+ // from the left side if it is more precise.
+ DartType contextType = InferenceContext.getType(node);
+ DartType leftType = leftOperand?.staticType;
+ if (contextType == null || contextType.isDynamic) {
+ contextType = leftType;
+ }
+ InferenceContext.setType(rightOperand, contextType);
+ }
rightOperand?.accept(this);
}
node.accept(elementResolver);
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698