| 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/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 3393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3404 '/main.dart': ''' | 3404 '/main.dart': ''' |
| 3405 import "a.dart"; | 3405 import "a.dart"; |
| 3406 | 3406 |
| 3407 test1() { | 3407 test1() { |
| 3408 int x = 0; | 3408 int x = 0; |
| 3409 x = new A().a2; | 3409 x = new A().a2; |
| 3410 } | 3410 } |
| 3411 ''' | 3411 ''' |
| 3412 }); | 3412 }); |
| 3413 DartType dynamicType = context.typeProvider.dynamicType; | 3413 DartType dynamicType = context.typeProvider.dynamicType; |
| 3414 DartType intType = context.typeProvider.intType; |
| 3414 | 3415 |
| 3415 computeResult( | 3416 computeResult( |
| 3416 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); | 3417 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); |
| 3417 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; | 3418 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; |
| 3418 | 3419 |
| 3419 // A.a2 should now be resolved on the rhs, but not yet inferred. | 3420 // A.a2 should now be resolved on the rhs, but not yet inferred. |
| 3420 assertVariableDeclarationTypes( | 3421 assertVariableDeclarationTypes( |
| 3421 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3422 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); |
| 3422 | 3423 |
| 3423 computeResult( | 3424 computeResult( |
| 3424 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); | 3425 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); |
| 3425 | 3426 |
| 3426 // A.a2 should now be fully resolved and inferred. | 3427 // A.a2 should now be fully resolved and inferred. |
| 3427 assertVariableDeclarationTypes( | 3428 assertVariableDeclarationTypes( |
| 3428 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3429 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3429 } | 3430 } |
| 3430 | 3431 |
| 3431 // Test inference of instance fields across units with cycles | 3432 // Test inference of instance fields across units with cycles |
| 3432 void test_perform_inference_cross_unit_static_instance() { | 3433 void test_perform_inference_cross_unit_static_instance() { |
| 3433 List<Source> sources = newSources({ | 3434 List<Source> sources = newSources({ |
| 3434 '/a.dart': ''' | 3435 '/a.dart': ''' |
| 3435 import 'b.dart'; | 3436 import 'b.dart'; |
| 3436 class A { | 3437 class A { |
| 3437 static final a1 = B.b1; | 3438 static final a1 = B.b1; |
| 3438 final a2 = new B().b2; | 3439 final a2 = new B().b2; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3530 | 3531 |
| 3531 // B.b2 shoud be resolved on the rhs, but not yet inferred. | 3532 // B.b2 shoud be resolved on the rhs, but not yet inferred. |
| 3532 assertVariableDeclarationTypes( | 3533 assertVariableDeclarationTypes( |
| 3533 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType); | 3534 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType); |
| 3534 | 3535 |
| 3535 computeResult( | 3536 computeResult( |
| 3536 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); | 3537 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); |
| 3537 | 3538 |
| 3538 // A.a2 should now be fully resolved and inferred. | 3539 // A.a2 should now be fully resolved and inferred. |
| 3539 assertVariableDeclarationTypes( | 3540 assertVariableDeclarationTypes( |
| 3540 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); | 3541 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); |
| 3541 | 3542 |
| 3542 // B.b2 should now be fully resolved and inferred. | 3543 // B.b2 should now be fully resolved and inferred. |
| 3543 assertVariableDeclarationTypes( | 3544 assertVariableDeclarationTypes( |
| 3544 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); | 3545 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 3545 } | 3546 } |
| 3546 } | 3547 } |
| 3547 | 3548 |
| 3548 @reflectiveTest | 3549 @reflectiveTest |
| 3549 class ResolveLibraryTaskTest extends _AbstractDartTaskTest { | 3550 class ResolveLibraryTaskTest extends _AbstractDartTaskTest { |
| 3550 test_perform() { | 3551 test_perform() { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3997 | 3998 |
| 3998 assertAssignmentStatementTypes(statements[1], intType, intType); | 3999 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 3999 assertAssignmentStatementTypes(statements[2], intType, intType); | 4000 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 4000 assertAssignmentStatementTypes(statements[3], intType, intType); | 4001 assertAssignmentStatementTypes(statements[3], intType, intType); |
| 4001 assertAssignmentStatementTypes(statements[4], intType, intType); | 4002 assertAssignmentStatementTypes(statements[4], intType, intType); |
| 4002 } | 4003 } |
| 4003 | 4004 |
| 4004 // Test that local variables in method bodies are inferred appropriately | 4005 // Test that local variables in method bodies are inferred appropriately |
| 4005 void test_perform_inference_cross_unit_instance() { | 4006 void test_perform_inference_cross_unit_instance() { |
| 4006 List<Source> sources = newSources({ | 4007 List<Source> sources = newSources({ |
| 4008 '/b.dart': ''' |
| 4009 class B { |
| 4010 final b2 = 1; |
| 4011 } |
| 4012 ''', |
| 4007 '/a.dart': ''' | 4013 '/a.dart': ''' |
| 4008 import 'b.dart'; | 4014 import 'b.dart'; |
| 4009 class A { | 4015 class A { |
| 4010 final a2 = new B().b2; | 4016 final a2 = new B().b2; |
| 4011 } | 4017 } |
| 4012 ''', | 4018 ''', |
| 4013 '/b.dart': ''' | |
| 4014 class B { | |
| 4015 final b2 = 1; | |
| 4016 } | |
| 4017 ''', | |
| 4018 '/main.dart': ''' | 4019 '/main.dart': ''' |
| 4019 import "a.dart"; | 4020 import "a.dart"; |
| 4020 | 4021 |
| 4021 test1() { | 4022 test1() { |
| 4022 int x = 0; | 4023 int x = 0; |
| 4023 x = new A().a2; | 4024 x = new A().a2; |
| 4024 } | 4025 } |
| 4025 ''' | 4026 ''' |
| 4026 }); | 4027 }); |
| 4027 List<dynamic> units = | 4028 List<dynamic> units = |
| 4028 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 4029 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 4029 CompilationUnit unit0 = units[0]; | 4030 CompilationUnit unit0 = units[0]; |
| 4030 CompilationUnit unit1 = units[1]; | 4031 CompilationUnit unit1 = units[1]; |
| 4031 CompilationUnit unit2 = units[2]; | 4032 CompilationUnit unit2 = units[2]; |
| 4032 | 4033 |
| 4033 InterfaceType intType = context.typeProvider.intType; | 4034 InterfaceType intType = context.typeProvider.intType; |
| 4034 | 4035 |
| 4035 assertVariableDeclarationTypes( | 4036 assertVariableDeclarationTypes( |
| 4036 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 4037 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 4037 | 4038 |
| 4038 assertVariableDeclarationTypes( | 4039 assertVariableDeclarationTypes( |
| 4039 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4040 AstFinder.getFieldInClass(unit1, "A", "a2"), intType, intType); |
| 4040 | 4041 |
| 4041 List<Statement> statements = | 4042 List<Statement> statements = |
| 4042 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4043 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4043 | 4044 |
| 4044 assertAssignmentStatementTypes(statements[1], intType, intType); | 4045 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 4045 } | 4046 } |
| 4046 | 4047 |
| 4047 // Test inference interactions between local variables and fields | 4048 // Test inference interactions between local variables and fields |
| 4048 void test_perform_inference_cross_unit_instance_member() { | 4049 void test_perform_inference_cross_unit_instance_member() { |
| 4049 List<Source> sources = newSources({ | 4050 List<Source> sources = newSources({ |
| 4050 '/a.dart': ''' | |
| 4051 import 'b.dart'; | |
| 4052 var bar = new B(); | |
| 4053 void foo() { | |
| 4054 String x = bar.f.z; | |
| 4055 } | |
| 4056 ''', | |
| 4057 '/b.dart': ''' | 4051 '/b.dart': ''' |
| 4058 class C { | 4052 class C { |
| 4059 var z = 3; | 4053 var z = 3; |
| 4060 } | 4054 } |
| 4061 | 4055 |
| 4062 class B { | 4056 class B { |
| 4063 var f = new C(); | 4057 var f = new C(); |
| 4064 } | 4058 } |
| 4065 ''', | 4059 ''', |
| 4060 '/a.dart': ''' |
| 4061 import 'b.dart'; |
| 4062 var bar = new B(); |
| 4063 void foo() { |
| 4064 String x = bar.f.z; |
| 4065 } |
| 4066 ''', |
| 4066 '/c.dart': ''' | 4067 '/c.dart': ''' |
| 4067 import 'b.dart'; | 4068 import 'b.dart'; |
| 4068 var bar = new B(); | 4069 var bar = new B(); |
| 4069 void foo() { | 4070 void foo() { |
| 4070 String x = bar.f.z; | 4071 String x = bar.f.z; |
| 4071 } | 4072 } |
| 4072 ''' | 4073 ''' |
| 4073 }); | 4074 }); |
| 4074 List<dynamic> units = | 4075 List<dynamic> units = |
| 4075 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 4076 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 4076 CompilationUnit unit0 = units[0]; | 4077 CompilationUnit unit1 = units[1]; |
| 4077 CompilationUnit unit2 = units[2]; | 4078 CompilationUnit unit2 = units[2]; |
| 4078 | 4079 |
| 4079 InterfaceType intType = context.typeProvider.intType; | 4080 InterfaceType intType = context.typeProvider.intType; |
| 4080 InterfaceType stringType = context.typeProvider.stringType; | 4081 InterfaceType stringType = context.typeProvider.stringType; |
| 4081 | 4082 |
| 4082 assertVariableDeclarationStatementTypes( | 4083 assertVariableDeclarationStatementTypes( |
| 4083 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0], | 4084 AstFinder.getStatementsInTopLevelFunction(unit1, "foo")[0], |
| 4084 stringType, | 4085 stringType, |
| 4085 intType); | 4086 intType); |
| 4086 assertVariableDeclarationStatementTypes( | 4087 assertVariableDeclarationStatementTypes( |
| 4087 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], | 4088 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], |
| 4088 stringType, | 4089 stringType, |
| 4089 intType); | 4090 intType); |
| 4090 } | 4091 } |
| 4091 | 4092 |
| 4092 // Test inference interactions between local variables and top level | 4093 // Test inference interactions between local variables and top level |
| 4093 // variables | 4094 // variables |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4135 List<Statement> statements = | 4136 List<Statement> statements = |
| 4136 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4137 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4137 | 4138 |
| 4138 assertAssignmentStatementTypes(statements[0], intType, stringType); | 4139 assertAssignmentStatementTypes(statements[0], intType, stringType); |
| 4139 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4140 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4140 } | 4141 } |
| 4141 | 4142 |
| 4142 // Test that inference does not propagate from null | 4143 // Test that inference does not propagate from null |
| 4143 void test_perform_inference_cross_unit_static_instance() { | 4144 void test_perform_inference_cross_unit_static_instance() { |
| 4144 List<Source> sources = newSources({ | 4145 List<Source> sources = newSources({ |
| 4146 '/b.dart': ''' |
| 4147 class B { |
| 4148 static final b1 = 1; |
| 4149 final b2 = 1; |
| 4150 } |
| 4151 ''', |
| 4145 '/a.dart': ''' | 4152 '/a.dart': ''' |
| 4146 import 'b.dart'; | 4153 import 'b.dart'; |
| 4147 class A { | 4154 class A { |
| 4148 static final a1 = B.b1; | 4155 static final a1 = B.b1; |
| 4149 final a2 = new B().b2; | 4156 final a2 = new B().b2; |
| 4150 } | 4157 } |
| 4151 ''', | 4158 ''', |
| 4152 '/b.dart': ''' | |
| 4153 class B { | |
| 4154 static final b1 = 1; | |
| 4155 final b2 = 1; | |
| 4156 } | |
| 4157 ''', | |
| 4158 '/main.dart': ''' | 4159 '/main.dart': ''' |
| 4159 import "a.dart"; | 4160 import "a.dart"; |
| 4160 | 4161 |
| 4161 test1() { | 4162 test1() { |
| 4162 int x = 0; | 4163 int x = 0; |
| 4163 // inference in A now works. | 4164 // inference in A now works. |
| 4164 x = A.a1; | 4165 x = A.a1; |
| 4165 x = new A().a2; | 4166 x = new A().a2; |
| 4166 } | 4167 } |
| 4167 ''' | 4168 ''' |
| 4168 }); | 4169 }); |
| 4169 List<dynamic> units = | 4170 List<dynamic> units = |
| 4170 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); | 4171 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); |
| 4171 CompilationUnit unit0 = units[0]; | 4172 CompilationUnit unit0 = units[0]; |
| 4172 CompilationUnit unit1 = units[1]; | 4173 CompilationUnit unit1 = units[1]; |
| 4173 CompilationUnit unit2 = units[2]; | 4174 CompilationUnit unit2 = units[2]; |
| 4174 | 4175 |
| 4175 InterfaceType intType = context.typeProvider.intType; | 4176 InterfaceType intType = context.typeProvider.intType; |
| 4176 | 4177 |
| 4177 assertVariableDeclarationTypes( | 4178 assertVariableDeclarationTypes( |
| 4178 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); | 4179 AstFinder.getFieldInClass(unit0, "B", "b1"), intType, intType); |
| 4179 assertVariableDeclarationTypes( | 4180 assertVariableDeclarationTypes( |
| 4180 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); | 4181 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 4181 | 4182 |
| 4182 assertVariableDeclarationTypes( | 4183 assertVariableDeclarationTypes( |
| 4183 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); | 4184 AstFinder.getFieldInClass(unit1, "A", "a1"), intType, intType); |
| 4184 assertVariableDeclarationTypes( | 4185 assertVariableDeclarationTypes( |
| 4185 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); | 4186 AstFinder.getFieldInClass(unit1, "A", "a2"), intType, intType); |
| 4186 | 4187 |
| 4187 List<Statement> statements = | 4188 List<Statement> statements = |
| 4188 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4189 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4189 | 4190 |
| 4190 assertAssignmentStatementTypes(statements[1], intType, intType); | 4191 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 4191 assertAssignmentStatementTypes(statements[2], intType, intType); | 4192 assertAssignmentStatementTypes(statements[2], intType, intType); |
| 4192 } | 4193 } |
| 4193 | 4194 |
| 4194 // Test inference across units (non-cyclic) | 4195 // Test inference across units (non-cyclic) |
| 4195 void test_perform_inference_local_variables() { | 4196 void test_perform_inference_local_variables() { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4654 /** | 4655 /** |
| 4655 * Fill [errorListener] with [result] errors in the current [task]. | 4656 * Fill [errorListener] with [result] errors in the current [task]. |
| 4656 */ | 4657 */ |
| 4657 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4658 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4658 List<AnalysisError> errors = task.outputs[result]; | 4659 List<AnalysisError> errors = task.outputs[result]; |
| 4659 expect(errors, isNotNull, reason: result.name); | 4660 expect(errors, isNotNull, reason: result.name); |
| 4660 errorListener = new GatheringErrorListener(); | 4661 errorListener = new GatheringErrorListener(); |
| 4661 errorListener.addAll(errors); | 4662 errorListener.addAll(errors); |
| 4662 } | 4663 } |
| 4663 } | 4664 } |
| OLD | NEW |