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 // TODO(jmesserly): this file needs to be refactored, it's a port from | 5 // TODO(jmesserly): this file needs to be refactored, it's a port from |
6 // package:dev_compiler's tests | 6 // package:dev_compiler's tests |
7 /// Tests for type inference. | 7 /// Tests for type inference. |
8 library analyzer.test.src.task.strong.inferred_type_test; | 8 library analyzer.test.src.task.strong.inferred_type_test; |
9 | 9 |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 3888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3899 class C { | 3899 class C { |
3900 C(_); | 3900 C(_); |
3901 int i; | 3901 int i; |
3902 } | 3902 } |
3903 '''); | 3903 '''); |
3904 // No type should be inferred for a because there is a circular reference | 3904 // No type should be inferred for a because there is a circular reference |
3905 // between a and c. | 3905 // between a and c. |
3906 } | 3906 } |
3907 | 3907 |
3908 void test_unsafeBlockClosureInference_closureCall() { | 3908 void test_unsafeBlockClosureInference_closureCall() { |
3909 // Note: this is a DYNAMIC_INVOKE due to dartbug.com/26962. | 3909 // Regression test for https://github.com/dart-lang/sdk/issues/26962 |
3910 var mainUnit = checkFile(''' | 3910 var mainUnit = checkFile(''' |
3911 var v = /*info:DYNAMIC_INVOKE*/((x) => 1.0)( | 3911 var v = ((x) => 1.0)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); |
3912 /*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); | |
3913 '''); | 3912 '''); |
3914 var v = mainUnit.topLevelVariables[0]; | 3913 var v = mainUnit.topLevelVariables[0]; |
3915 expect(v.name, 'v'); | 3914 expect(v.name, 'v'); |
3916 expect(v.type.toString(), 'double'); | 3915 expect(v.type.toString(), 'double'); |
3917 } | 3916 } |
3918 | 3917 |
3919 void test_unsafeBlockClosureInference_constructorCall_explicitDynamicParam() { | 3918 void test_unsafeBlockClosureInference_constructorCall_explicitDynamicParam() { |
3920 var mainUnit = checkFile(''' | 3919 var mainUnit = checkFile(''' |
3921 class C<T> { | 3920 class C<T> { |
3922 C(T x()); | 3921 C(T x()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4068 var mainUnit = checkFile(''' | 4067 var mainUnit = checkFile(''' |
4069 double f(x) => 1.0; | 4068 double f(x) => 1.0; |
4070 var v = f(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); | 4069 var v = f(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); |
4071 '''); | 4070 '''); |
4072 var v = mainUnit.topLevelVariables[0]; | 4071 var v = mainUnit.topLevelVariables[0]; |
4073 expect(v.name, 'v'); | 4072 expect(v.name, 'v'); |
4074 expect(v.type.toString(), 'double'); | 4073 expect(v.type.toString(), 'double'); |
4075 } | 4074 } |
4076 | 4075 |
4077 void test_unsafeBlockClosureInference_functionCall_noTypeParam_viaExpr() { | 4076 void test_unsafeBlockClosureInference_functionCall_noTypeParam_viaExpr() { |
4078 // TODO(paulberry): why is the call to f() considered a DYNAMIC_INVOKE? | |
4079 var mainUnit = checkFile(''' | 4077 var mainUnit = checkFile(''' |
4080 double f(x) => 1.0; | 4078 double f(x) => 1.0; |
4081 var v = /*info:DYNAMIC_INVOKE*/(f)( | 4079 var v = (f)(/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); |
4082 /*info:INFERRED_TYPE_CLOSURE*/() { return 1; }); | |
4083 '''); | 4080 '''); |
4084 var v = mainUnit.topLevelVariables[0]; | 4081 var v = mainUnit.topLevelVariables[0]; |
4085 expect(v.name, 'v'); | 4082 expect(v.name, 'v'); |
4086 expect(v.type.toString(), 'double'); | 4083 expect(v.type.toString(), 'double'); |
4087 } | 4084 } |
4088 | 4085 |
4089 void test_unsafeBlockClosureInference_inList_dynamic() { | 4086 void test_unsafeBlockClosureInference_inList_dynamic() { |
4090 var mainUnit = checkFile(''' | 4087 var mainUnit = checkFile(''' |
4091 var v = <dynamic>[/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }]; | 4088 var v = <dynamic>[/*info:INFERRED_TYPE_CLOSURE*/() { return 1; }]; |
4092 '''); | 4089 '''); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4229 } | 4226 } |
4230 | 4227 |
4231 /// Adds a file using [helper.addFile] and calls [helper.check]. | 4228 /// Adds a file using [helper.addFile] and calls [helper.check]. |
4232 /// | 4229 /// |
4233 /// Also returns the resolved compilation unit. | 4230 /// Also returns the resolved compilation unit. |
4234 @override | 4231 @override |
4235 CompilationUnitElement checkFile(String content) { | 4232 CompilationUnitElement checkFile(String content) { |
4236 return helper.checkFile(content).element; | 4233 return helper.checkFile(content).element; |
4237 } | 4234 } |
4238 } | 4235 } |
OLD | NEW |