This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,9 @@ class RestrictedResolverVisitor extends ResolverVisitor {
110
110
/// in the restricted type system and to infer types for untyped local
111
111
/// variables.
112
112
class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer {
113
- RestrictedStaticTypeAnalyzer (ResolverVisitor r) : super (r);
113
+ final DartType _bottomType;
114
+ RestrictedStaticTypeAnalyzer (ResolverVisitor r)
115
+ : _bottomType = r.typeProvider.bottomType, super (r);
114
116
115
117
@override // to infer type from initializers
116
118
Object visitVariableDeclaration (VariableDeclaration node) {
@@ -128,8 +130,9 @@ class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer {
128
130
if (declaredType != null ) return ;
129
131
VariableElementImpl element = node.element;
130
132
if (element.type != dynamicType) return ;
131
- element.type = getStaticType (initializer);
132
- return ;
133
+ var type = getStaticType (initializer);
134
+ if (type == _bottomType) return ;
135
+ element.type = type;
133
136
}
134
137
135
138
@override // to propagate types to identifiers
Original file line number Diff line number Diff line change @@ -41,6 +41,18 @@ main() {
41
41
});
42
42
});
43
43
44
+ test ('do not infer type when initializer is null' , () {
45
+ testChecker ({
46
+ '/main.dart' : '''
47
+ test() {
48
+ var x = null;
49
+ x = "hi";
50
+ x = /*config:Box*/3;
51
+ }
52
+ '''
53
+ });
54
+ });
55
+
44
56
test ('propagate inference to field in class' , () {
45
57
testChecker ({
46
58
'/main.dart' : '''
You can’t perform that action at this time.
0 commit comments