OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.generated.strong_mode_test; | 5 library analyzer.test.generated.strong_mode_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
(...skipping 3136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3147 '''; | 3147 '''; |
3148 await resolveTestUnit(code); | 3148 await resolveTestUnit(code); |
3149 expectIdentifierType('ai', "A<dynamic>"); | 3149 expectIdentifierType('ai', "A<dynamic>"); |
3150 expectIdentifierType('bi', "B<num>"); | 3150 expectIdentifierType('bi', "B<num>"); |
3151 expectIdentifierType('ci', "C<int, B<int>, A<dynamic>>"); | 3151 expectIdentifierType('ci', "C<int, B<int>, A<dynamic>>"); |
3152 expectIdentifierType('aa', "A<dynamic>"); | 3152 expectIdentifierType('aa', "A<dynamic>"); |
3153 expectIdentifierType('bb', "B<num>"); | 3153 expectIdentifierType('bb', "B<num>"); |
3154 expectIdentifierType('cc', "C<int, B<int>, A<dynamic>>"); | 3154 expectIdentifierType('cc', "C<int, B<int>, A<dynamic>>"); |
3155 } | 3155 } |
3156 | 3156 |
| 3157 test_inferClosureType_parameters() async { |
| 3158 Source source = addSource(r''' |
| 3159 typedef F({bool p}); |
| 3160 foo(callback(F f)) {} |
| 3161 main() { |
| 3162 foo((f) { |
| 3163 f(p: false); |
| 3164 }); |
| 3165 } |
| 3166 '''); |
| 3167 var result = await computeAnalysisResult(source); |
| 3168 var main = result.unit.declarations[2] as FunctionDeclaration; |
| 3169 var body = main.functionExpression.body as BlockFunctionBody; |
| 3170 var statement = body.block.statements[0] as ExpressionStatement; |
| 3171 var invocation = statement.expression as MethodInvocation; |
| 3172 var closure = invocation.argumentList.arguments[0] as FunctionExpression; |
| 3173 var closureType = closure.staticType as FunctionType; |
| 3174 var fType = closureType.parameters[0].type as FunctionType; |
| 3175 // The inferred type of "f" in "foo()" invocation must own its parameters. |
| 3176 ParameterElement p = fType.parameters[0]; |
| 3177 expect(p.name, 'p'); |
| 3178 expect(p.enclosingElement, same(fType.element)); |
| 3179 } |
| 3180 |
3157 @failingTest | 3181 @failingTest |
3158 test_instantiateToBounds_class_error_extension_malbounded() async { | 3182 test_instantiateToBounds_class_error_extension_malbounded() async { |
3159 // Test that superclasses are strictly checked for malbounded default | 3183 // Test that superclasses are strictly checked for malbounded default |
3160 // types | 3184 // types |
3161 String code = r''' | 3185 String code = r''' |
3162 class C<T0 extends List<T1>, T1 extends List<T0>> {} | 3186 class C<T0 extends List<T1>, T1 extends List<T0>> {} |
3163 class D extends C {} | 3187 class D extends C {} |
3164 '''; | 3188 '''; |
3165 await resolveTestUnit(code, noErrors: false); | 3189 await resolveTestUnit(code, noErrors: false); |
3166 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]); | 3190 assertErrors(testSource, [StrongModeCode.NO_DEFAULT_BOUNDS]); |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3897 var v = x; | 3921 var v = x; |
3898 v; // marker | 3922 v; // marker |
3899 } | 3923 } |
3900 int x = 3; | 3924 int x = 3; |
3901 '''; | 3925 '''; |
3902 CompilationUnit unit = await resolveSource(code); | 3926 CompilationUnit unit = await resolveSource(code); |
3903 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); | 3927 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
3904 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | 3928 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); |
3905 } | 3929 } |
3906 } | 3930 } |
OLD | NEW |