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

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

Issue 2210293002: infer null from context, this avoids bottom being introduced (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index f68147180e5529973e12766669e0348cd963a001..9f4aa69f923023697973a431b924f09849a2e168 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -1029,8 +1029,18 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
*/
@override
Object visitNullLiteral(NullLiteral node) {
- // TODO(jmesserly): in strong mode, should we just use the context type?
- _recordStaticType(node, _typeProvider.bottomType);
+ DartType type;
+ if (_strongMode) {
+ // In strong mode, we use the surrounding context type if we have one.
+ //
+ // Otherwise we use dynamic, because that's what we want to be inferred
+ // by default. For example in `var x = null;` the type of `x` is dynamic.
+ type = InferenceContext.getType(node) ?? _typeProvider.dynamicType;
+ } else {
+ // In Dart 1, null is bottom to make it assignable to everything.
+ type = _typeProvider.bottomType;
+ }
+ _recordStaticType(node, type);
return null;
}
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/strong_mode_test.dart » ('j') | pkg/analyzer/test/generated/strong_mode_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698