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 analyzer.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
(...skipping 3460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3471 | 3471 |
3472 // A.a2 should now be resolved on the rhs, but not yet inferred. | 3472 // A.a2 should now be resolved on the rhs, but not yet inferred. |
3473 assertVariableDeclarationTypes( | 3473 assertVariableDeclarationTypes( |
3474 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 3474 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
3475 | 3475 |
3476 computeResult( | 3476 computeResult( |
3477 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); | 3477 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
3478 | 3478 |
3479 // A.a2 should now be fully resolved and inferred. | 3479 // A.a2 should now be fully resolved and inferred. |
3480 assertVariableDeclarationTypes( | 3480 assertVariableDeclarationTypes( |
3481 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 3481 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
3482 | 3482 |
3483 assertVariableDeclarationTypes( | 3483 assertVariableDeclarationTypes( |
3484 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 3484 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
3485 } | 3485 } |
3486 | 3486 |
3487 /** | 3487 /** |
3488 * Test inference of instance fields across units | 3488 * Test inference of instance fields across units |
3489 */ | 3489 */ |
3490 void test_perform_inference_cross_unit_instance_cyclic() { | 3490 void test_perform_inference_cross_unit_instance_cyclic() { |
3491 List<Source> sources = newSources({ | 3491 List<Source> sources = newSources({ |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 3582 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
3583 assertVariableDeclarationTypes( | 3583 assertVariableDeclarationTypes( |
3584 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 3584 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
3585 | 3585 |
3586 computeResult( | 3586 computeResult( |
3587 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); | 3587 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9); |
3588 | 3588 |
3589 assertVariableDeclarationTypes( | 3589 assertVariableDeclarationTypes( |
3590 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); | 3590 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
3591 assertVariableDeclarationTypes( | 3591 assertVariableDeclarationTypes( |
3592 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 3592 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
3593 | 3593 |
3594 assertVariableDeclarationTypes( | 3594 assertVariableDeclarationTypes( |
3595 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 3595 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
3596 assertVariableDeclarationTypes( | 3596 assertVariableDeclarationTypes( |
3597 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 3597 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
3598 } | 3598 } |
3599 | 3599 |
3600 /** | 3600 /** |
3601 * Test inference between static and instance fields | 3601 * Test inference between static and instance fields |
3602 */ | 3602 */ |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4285 } | 4285 } |
4286 ''' | 4286 ''' |
4287 }); | 4287 }); |
4288 List<dynamic> units = | 4288 List<dynamic> units = |
4289 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); | 4289 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
4290 CompilationUnit unit0 = units[0]; | 4290 CompilationUnit unit0 = units[0]; |
4291 CompilationUnit unit1 = units[1]; | 4291 CompilationUnit unit1 = units[1]; |
4292 CompilationUnit unit2 = units[2]; | 4292 CompilationUnit unit2 = units[2]; |
4293 | 4293 |
4294 InterfaceType intType = context.typeProvider.intType; | 4294 InterfaceType intType = context.typeProvider.intType; |
4295 DartType dynamicType = context.typeProvider.dynamicType; | |
4296 | 4295 |
4297 assertVariableDeclarationTypes( | 4296 assertVariableDeclarationTypes( |
4298 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 4297 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
4299 | 4298 |
4300 assertVariableDeclarationTypes( | 4299 assertVariableDeclarationTypes( |
4301 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4300 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
4302 | 4301 |
4303 List<Statement> statements = | 4302 List<Statement> statements = |
4304 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4303 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
4305 | 4304 |
4306 assertAssignmentStatementTypes(statements[1], intType, dynamicType); | 4305 assertAssignmentStatementTypes(statements[1], intType, intType); |
4307 } | 4306 } |
4308 | 4307 |
4309 // Test inference interactions between local variables and fields | 4308 // Test inference interactions between local variables and fields |
4310 void test_perform_inference_cross_unit_instance_member() { | 4309 void test_perform_inference_cross_unit_instance_member() { |
4311 List<Source> sources = newSources({ | 4310 List<Source> sources = newSources({ |
4312 '/a.dart': ''' | 4311 '/a.dart': ''' |
4313 import 'b.dart'; | 4312 import 'b.dart'; |
4314 var bar = new B(); | 4313 var bar = new B(); |
4315 void foo() { | 4314 void foo() { |
4316 String x = bar.f.z; | 4315 String x = bar.f.z; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4424 } | 4423 } |
4425 ''' | 4424 ''' |
4426 }); | 4425 }); |
4427 List<dynamic> units = | 4426 List<dynamic> units = |
4428 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); | 4427 computeLibraryResults(sources, RESOLVED_UNIT11).toList(); |
4429 CompilationUnit unit0 = units[0]; | 4428 CompilationUnit unit0 = units[0]; |
4430 CompilationUnit unit1 = units[1]; | 4429 CompilationUnit unit1 = units[1]; |
4431 CompilationUnit unit2 = units[2]; | 4430 CompilationUnit unit2 = units[2]; |
4432 | 4431 |
4433 InterfaceType intType = context.typeProvider.intType; | 4432 InterfaceType intType = context.typeProvider.intType; |
4434 DartType dynamicType = context.typeProvider.dynamicType; | |
4435 | 4433 |
4436 assertVariableDeclarationTypes( | 4434 assertVariableDeclarationTypes( |
4437 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); | 4435 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); |
4438 assertVariableDeclarationTypes( | 4436 assertVariableDeclarationTypes( |
4439 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); | 4437 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); |
4440 | 4438 |
4441 assertVariableDeclarationTypes( | 4439 assertVariableDeclarationTypes( |
4442 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 4440 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); |
4443 assertVariableDeclarationTypes( | 4441 assertVariableDeclarationTypes( |
4444 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4442 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); |
4445 | 4443 |
4446 List<Statement> statements = | 4444 List<Statement> statements = |
4447 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4445 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
4448 | 4446 |
4449 assertAssignmentStatementTypes(statements[1], intType, intType); | 4447 assertAssignmentStatementTypes(statements[1], intType, intType); |
4450 assertAssignmentStatementTypes(statements[2], intType, dynamicType); | 4448 assertAssignmentStatementTypes(statements[2], intType, intType); |
4451 } | 4449 } |
4452 | 4450 |
4453 // Test inference across units (non-cyclic) | 4451 // Test inference across units (non-cyclic) |
4454 void test_perform_inference_local_variables() { | 4452 void test_perform_inference_local_variables() { |
4455 AnalysisTarget source = newSource('/test.dart', ''' | 4453 AnalysisTarget source = newSource('/test.dart', ''' |
4456 test() { | 4454 test() { |
4457 int x = 3; | 4455 int x = 3; |
4458 x = "hi"; | 4456 x = "hi"; |
4459 var y = 3; | 4457 var y = 3; |
4460 y = "hi"; | 4458 y = "hi"; |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4983 /** | 4981 /** |
4984 * Fill [errorListener] with [result] errors in the current [task]. | 4982 * Fill [errorListener] with [result] errors in the current [task]. |
4985 */ | 4983 */ |
4986 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4984 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
4987 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 4985 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
4988 expect(errors, isNotNull, reason: result.name); | 4986 expect(errors, isNotNull, reason: result.name); |
4989 errorListener = new GatheringErrorListener(); | 4987 errorListener = new GatheringErrorListener(); |
4990 errorListener.addAll(errors); | 4988 errorListener.addAll(errors); |
4991 } | 4989 } |
4992 } | 4990 } |
OLD | NEW |