OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library test.src.task.strong_mode_test; | 5 library test.src.task.strong_mode_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:analyzer/src/task/strong_mode.dart'; | 10 import 'package:analyzer/src/task/strong_mode.dart'; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 PropertyAccessorElement getterB = classB.getGetter(fieldName); | 234 PropertyAccessorElement getterB = classB.getGetter(fieldName); |
235 expect(fieldB.type.isDynamic, isTrue); | 235 expect(fieldB.type.isDynamic, isTrue); |
236 expect(getterB.returnType.isDynamic, isTrue); | 236 expect(getterB.returnType.isDynamic, isTrue); |
237 | 237 |
238 inferrer.inferCompilationUnit(unit); | 238 inferrer.inferCompilationUnit(unit); |
239 | 239 |
240 expect(fieldB.type, fieldA.type); | 240 expect(fieldB.type, fieldA.type); |
241 expect(getterB.returnType, getterA.returnType); | 241 expect(getterB.returnType, getterA.returnType); |
242 } | 242 } |
243 | 243 |
| 244 void test_inferCompilationUnit_field_single_final_narrowType() { |
| 245 InstanceMemberInferrer inferrer = createInferrer; |
| 246 String fieldName = 'f'; |
| 247 CompilationUnitElement unit = resolve(''' |
| 248 class A { |
| 249 final $fieldName; |
| 250 } |
| 251 class B extends A { |
| 252 final $fieldName = 0; |
| 253 } |
| 254 '''); |
| 255 ClassElement classA = unit.getType('A'); |
| 256 FieldElement fieldA = classA.getField(fieldName); |
| 257 PropertyAccessorElement getterA = classA.getGetter(fieldName); |
| 258 ClassElement classB = unit.getType('B'); |
| 259 FieldElement fieldB = classB.getField(fieldName); |
| 260 PropertyAccessorElement getterB = classB.getGetter(fieldName); |
| 261 expect(fieldB.type.isDynamic, isTrue); |
| 262 expect(getterB.returnType.isDynamic, isTrue); |
| 263 |
| 264 inferrer.inferCompilationUnit(unit); |
| 265 |
| 266 expect(fieldB.type, inferrer.typeProvider.intType); |
| 267 expect(getterB.returnType, fieldB.type); |
| 268 } |
| 269 |
244 void test_inferCompilationUnit_field_single_generic() { | 270 void test_inferCompilationUnit_field_single_generic() { |
245 InstanceMemberInferrer inferrer = createInferrer; | 271 InstanceMemberInferrer inferrer = createInferrer; |
246 String fieldName = 'f'; | 272 String fieldName = 'f'; |
247 CompilationUnitElement unit = resolve(''' | 273 CompilationUnitElement unit = resolve(''' |
248 class A<E> { | 274 class A<E> { |
249 E $fieldName; | 275 E $fieldName; |
250 } | 276 } |
251 class B<E> extends A<E> { | 277 class B<E> extends A<E> { |
252 var $fieldName; | 278 var $fieldName; |
253 } | 279 } |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 } | 1021 } |
996 } | 1022 } |
997 } | 1023 } |
998 '''); | 1024 '''); |
999 CompilationUnit unit = context.resolveCompilationUnit2(source, source); | 1025 CompilationUnit unit = context.resolveCompilationUnit2(source, source); |
1000 VariableGatherer gatherer = new VariableGatherer(filter); | 1026 VariableGatherer gatherer = new VariableGatherer(filter); |
1001 unit.accept(gatherer); | 1027 unit.accept(gatherer); |
1002 return gatherer.results; | 1028 return gatherer.results; |
1003 } | 1029 } |
1004 } | 1030 } |
OLD | NEW |