Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 13003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13014 check("f2", _isListOf(_isInt)); | 13014 check("f2", _isListOf(_isInt)); |
| 13015 check("f3", _isListOf(_isListOf(_isInt))); | 13015 check("f3", _isListOf(_isListOf(_isInt))); |
| 13016 } | 13016 } |
| 13017 } | 13017 } |
| 13018 | 13018 |
| 13019 /** | 13019 /** |
| 13020 * Strong mode static analyzer end to end tests | 13020 * Strong mode static analyzer end to end tests |
| 13021 */ | 13021 */ |
| 13022 @reflectiveTest | 13022 @reflectiveTest |
| 13023 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { | 13023 class StrongModeStaticTypeAnalyzer2Test extends _StaticTypeAnalyzer2TestShared { |
| 13024 void test_genericFunction_parameter() { | |
| 13025 _resolveTestUnit(r''' | |
| 13026 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} | |
| 13027 '''); | |
| 13028 SimpleIdentifier f = _findIdentifier('f'); | |
| 13029 ParameterElementImpl e = f.staticElement; | |
| 13030 FunctionType type = e.type; | |
| 13031 expect(e.typeParameters.toString(), '[T]'); | |
| 13032 expect(type.boundTypeParameters.toString(), '[T]'); | |
| 13033 expect(type.toString(), '<T>(T) → T'); | |
| 13034 FunctionType ft = type.instantiate([typeProvider.stringType]); | |
| 13035 expect(ft.toString(), '(String) → String'); | |
| 13036 } | |
| 13037 | |
| 13038 void fail_genericMethod_functionExpressionInvocation_explicit() { | 13024 void fail_genericMethod_functionExpressionInvocation_explicit() { |
| 13039 _resolveTestUnit(r''' | 13025 _resolveTestUnit(r''' |
| 13040 class C<E> { | 13026 class C<E> { |
| 13041 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13027 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13042 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13028 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13043 static final h = g; | 13029 static final h = g; |
| 13044 } | 13030 } |
| 13045 | 13031 |
| 13046 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13032 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13047 var topG = topF; | 13033 var topG = topF; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13090 '''); | 13076 '''); |
| 13091 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13077 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13092 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13078 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13093 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13079 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13094 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13080 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13095 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13081 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13096 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13082 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13097 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13083 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13098 } | 13084 } |
| 13099 | 13085 |
| 13100 void fail_genericMethod_functionInvocation_explicit() { | |
| 13101 _resolveTestUnit(r''' | |
| 13102 class C<E> { | |
| 13103 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | |
| 13104 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13105 static final h = g; | |
| 13106 } | |
| 13107 | |
| 13108 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13109 var topG = topF; | |
| 13110 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13111 var c = new C<int>(); | |
| 13112 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13113 var methodCall = c.f/*<int>*/(3); | |
| 13114 var staticCall = C.g/*<int>*/(3); | |
| 13115 var staticFieldCall = C.h/*<int>*/(3); | |
| 13116 var topFunCall = topF/*<int>*/(3); | |
| 13117 var topFieldCall = topG/*<int>*/(3); | |
| 13118 var localCall = lf/*<int>*/(3); | |
| 13119 var paramCall = pf/*<int>*/(3); | |
| 13120 } | |
| 13121 '''); | |
| 13122 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | |
| 13123 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | |
| 13124 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | |
| 13125 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | |
| 13126 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | |
| 13127 expect(_findIdentifier('localCall').staticType.toString(), "int"); | |
| 13128 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | |
| 13129 } | |
| 13130 | |
| 13131 void fail_genericMethod_functionInvocation_inferred() { | 13086 void fail_genericMethod_functionInvocation_inferred() { |
| 13132 _resolveTestUnit(r''' | 13087 _resolveTestUnit(r''' |
| 13133 class C<E> { | 13088 class C<E> { |
| 13134 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | 13089 /*=T*/ f/*<T>*/(/*=T*/ e) => null; |
| 13135 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13090 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13136 static final h = g; | 13091 static final h = g; |
| 13137 } | 13092 } |
| 13138 | 13093 |
| 13139 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13094 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13140 var topG = topF; | 13095 var topG = topF; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 13152 '''); | 13107 '''); |
| 13153 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | 13108 expect(_findIdentifier('methodCall').staticType.toString(), "int"); |
| 13154 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | 13109 expect(_findIdentifier('staticCall').staticType.toString(), "int"); |
| 13155 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | 13110 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); |
| 13156 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | 13111 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); |
| 13157 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | 13112 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); |
| 13158 expect(_findIdentifier('localCall').staticType.toString(), "int"); | 13113 expect(_findIdentifier('localCall').staticType.toString(), "int"); |
| 13159 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | 13114 expect(_findIdentifier('paramCall').staticType.toString(), "int"); |
| 13160 } | 13115 } |
| 13161 | 13116 |
| 13162 void test_genericMethod_tearoff() { | |
| 13163 _resolveTestUnit(r''' | |
| 13164 class C<E> { | |
| 13165 /*=T*/ f/*<T>*/(E e) => null; | |
| 13166 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13167 static final h = g; | |
| 13168 } | |
| 13169 | |
| 13170 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13171 var topG = topF; | |
| 13172 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13173 var c = new C<int>(); | |
| 13174 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13175 var methodTearOff = c.f; | |
| 13176 var staticTearOff = C.g; | |
| 13177 var staticFieldTearOff = C.h; | |
| 13178 var topFunTearOff = topF; | |
| 13179 var topFieldTearOff = topG; | |
| 13180 var localTearOff = lf; | |
| 13181 var paramTearOff = pf; | |
| 13182 } | |
| 13183 '''); | |
| 13184 expect( | |
| 13185 _findIdentifier('methodTearOff').staticType.toString(), "<T>(int) → T"); | |
| 13186 expect( | |
| 13187 _findIdentifier('staticTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13188 expect(_findIdentifier('staticFieldTearOff').staticType.toString(), | |
| 13189 "<T>(T) → T"); | |
| 13190 expect( | |
| 13191 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13192 expect( | |
| 13193 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13194 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13195 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13196 } | |
| 13197 | |
| 13198 void fail_genericMethod_tearoff_instantiated() { | 13117 void fail_genericMethod_tearoff_instantiated() { |
| 13199 _resolveTestUnit(r''' | 13118 _resolveTestUnit(r''' |
| 13200 class C<E> { | 13119 class C<E> { |
| 13201 /*=T*/ f/*<T>*/(E e) => null; | 13120 /*=T*/ f/*<T>*/(E e) => null; |
| 13202 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 13121 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| 13203 static final h = g; | 13122 static final h = g; |
| 13204 } | 13123 } |
| 13205 | 13124 |
| 13206 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | 13125 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; |
| 13207 var topG = topF; | 13126 var topG = topF; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13270 identifier.getAncestor((node) => node is VariableDeclaration); | 13189 identifier.getAncestor((node) => node is VariableDeclaration); |
| 13271 expect(declaration.initializer.staticType.name, 'String'); | 13190 expect(declaration.initializer.staticType.name, 'String'); |
| 13272 expect(declaration.initializer.propagatedType, isNull); | 13191 expect(declaration.initializer.propagatedType, isNull); |
| 13273 } | 13192 } |
| 13274 | 13193 |
| 13275 void test_genericFunction() { | 13194 void test_genericFunction() { |
| 13276 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); | 13195 _resolveTestUnit(r'/*=T*/ f/*<T>*/(/*=T*/ x) => null;'); |
| 13277 SimpleIdentifier f = _findIdentifier('f'); | 13196 SimpleIdentifier f = _findIdentifier('f'); |
| 13278 FunctionElementImpl e = f.staticElement; | 13197 FunctionElementImpl e = f.staticElement; |
| 13279 expect(e.typeParameters.toString(), '[T]'); | 13198 expect(e.typeParameters.toString(), '[T]'); |
| 13280 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13199 expect(e.type.typeFormals.toString(), '[T]'); |
| 13281 expect(e.type.typeParameters.toString(), '[]'); | 13200 expect(e.type.typeParameters.toString(), '[]'); |
| 13282 expect(e.type.toString(), '<T>(T) → T'); | 13201 expect(e.type.toString(), '<T>(T) → T'); |
| 13283 | 13202 |
| 13284 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13203 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13285 expect(ft.toString(), '(String) → String'); | 13204 expect(ft.toString(), '(String) → String'); |
| 13286 } | 13205 } |
| 13287 | 13206 |
| 13288 void test_genericFunction_bounds() { | 13207 void test_genericFunction_bounds() { |
| 13289 _resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); | 13208 _resolveTestUnit(r'/*=T*/ f/*<T extends num>*/(/*=T*/ x) => null;'); |
| 13290 SimpleIdentifier f = _findIdentifier('f'); | 13209 SimpleIdentifier f = _findIdentifier('f'); |
| 13291 FunctionElementImpl e = f.staticElement; | 13210 FunctionElementImpl e = f.staticElement; |
| 13292 expect(e.typeParameters.toString(), '[T extends num]'); | 13211 expect(e.typeParameters.toString(), '[T extends num]'); |
| 13293 expect(e.type.boundTypeParameters.toString(), '[T extends num]'); | 13212 expect(e.type.typeFormals.toString(), '[T extends num]'); |
| 13294 expect(e.type.typeParameters.toString(), '[]'); | 13213 expect(e.type.typeParameters.toString(), '[]'); |
| 13295 expect(e.type.toString(), '<T extends num>(T) → T'); | 13214 expect(e.type.toString(), '<T extends num>(T) → T'); |
| 13296 } | 13215 } |
| 13297 | 13216 |
| 13217 void test_genericFunction_parameter() { | |
| 13218 _resolveTestUnit(r''' | |
| 13219 void g(/*=T*/ f/*<T>*/(/*=T*/ x)) {} | |
| 13220 '''); | |
| 13221 SimpleIdentifier f = _findIdentifier('f'); | |
| 13222 ParameterElementImpl e = f.staticElement; | |
| 13223 FunctionType type = e.type; | |
| 13224 expect(e.typeParameters.toString(), '[T]'); | |
| 13225 expect(type.boundTypeParameters.toString(), '[T]'); | |
| 13226 expect(type.toString(), '<T>(T) → T'); | |
| 13227 FunctionType ft = type.instantiate([typeProvider.stringType]); | |
| 13228 expect(ft.toString(), '(String) → String'); | |
| 13229 } | |
| 13230 | |
| 13298 void test_genericFunction_static() { | 13231 void test_genericFunction_static() { |
| 13299 _resolveTestUnit(r''' | 13232 _resolveTestUnit(r''' |
| 13300 class C<E> { | 13233 class C<E> { |
| 13301 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 13234 static /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 13302 } | 13235 } |
| 13303 '''); | 13236 '''); |
| 13304 SimpleIdentifier f = _findIdentifier('f'); | 13237 SimpleIdentifier f = _findIdentifier('f'); |
| 13305 MethodElementImpl e = f.staticElement; | 13238 MethodElementImpl e = f.staticElement; |
| 13306 expect(e.typeParameters.toString(), '[T]'); | 13239 expect(e.typeParameters.toString(), '[T]'); |
| 13307 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13240 expect(e.type.typeFormals.toString(), '[T]'); |
| 13308 // TODO(jmesserly): we could get rid of this {E/E} substitution, but it's | 13241 // TODO(jmesserly): we could get rid of this {E/E} substitution, but it's |
| 13309 // probably harmless, as E won't be used in the function (error verifier | 13242 // probably harmless, as E won't be used in the function (error verifier |
| 13310 // checks this), and {E/E} is a no-op anyway. | 13243 // checks this), and {E/E} is a no-op anyway. |
| 13311 expect(e.type.typeParameters.toString(), '[E]'); | 13244 expect(e.type.typeParameters.toString(), '[E]'); |
| 13312 expect(e.type.typeArguments.toString(), '[E]'); | 13245 expect(e.type.typeArguments.toString(), '[E]'); |
| 13313 expect(e.type.toString(), '<T>(T) → T'); | 13246 expect(e.type.toString(), '<T>(T) → T'); |
| 13314 | 13247 |
| 13315 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13248 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13316 expect(ft.toString(), '(String) → String'); | 13249 expect(ft.toString(), '(String) → String'); |
| 13317 } | 13250 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13396 class C<E> { | 13329 class C<E> { |
| 13397 List/*<T>*/ f/*<T>*/(E e) => null; | 13330 List/*<T>*/ f/*<T>*/(E e) => null; |
| 13398 } | 13331 } |
| 13399 main() { | 13332 main() { |
| 13400 C<String> cOfString; | 13333 C<String> cOfString; |
| 13401 } | 13334 } |
| 13402 '''); | 13335 '''); |
| 13403 SimpleIdentifier f = _findIdentifier('f'); | 13336 SimpleIdentifier f = _findIdentifier('f'); |
| 13404 MethodElementImpl e = f.staticElement; | 13337 MethodElementImpl e = f.staticElement; |
| 13405 expect(e.typeParameters.toString(), '[T]'); | 13338 expect(e.typeParameters.toString(), '[T]'); |
| 13406 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13339 expect(e.type.typeFormals.toString(), '[T]'); |
| 13407 expect(e.type.typeParameters.toString(), '[E]'); | 13340 expect(e.type.typeParameters.toString(), '[E]'); |
| 13408 expect(e.type.typeArguments.toString(), '[E]'); | 13341 expect(e.type.typeArguments.toString(), '[E]'); |
| 13409 expect(e.type.toString(), '<T>(E) → List<T>'); | 13342 expect(e.type.toString(), '<T>(E) → List<T>'); |
| 13410 | 13343 |
| 13411 SimpleIdentifier c = _findIdentifier('cOfString'); | 13344 SimpleIdentifier c = _findIdentifier('cOfString'); |
| 13412 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 13345 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 13413 expect(ft.toString(), '<T>(String) → List<T>'); | 13346 expect(ft.toString(), '<T>(String) → List<T>'); |
| 13414 ft = ft.instantiate([typeProvider.intType]); | 13347 ft = ft.instantiate([typeProvider.intType]); |
| 13415 expect(ft.toString(), '(String) → List<int>'); | 13348 expect(ft.toString(), '(String) → List<int>'); |
| 13416 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13349 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13417 } | 13350 } |
| 13418 | 13351 |
| 13419 void test_genericMethod_explicitTypeParams() { | 13352 void test_genericMethod_explicitTypeParams() { |
| 13420 _resolveTestUnit(r''' | 13353 _resolveTestUnit(r''' |
| 13421 class C<E> { | 13354 class C<E> { |
| 13422 List/*<T>*/ f/*<T>*/(E e) => null; | 13355 List/*<T>*/ f/*<T>*/(E e) => null; |
| 13423 } | 13356 } |
| 13424 main() { | 13357 main() { |
| 13425 C<String> cOfString; | 13358 C<String> cOfString; |
| 13426 var x = cOfString.f/*<int>*/('hi'); | 13359 var x = cOfString.f/*<int>*/('hi'); |
| 13427 } | 13360 } |
| 13428 '''); | 13361 '''); |
| 13429 SimpleIdentifier f = _findIdentifier('f/*<int>*/'); | 13362 MethodInvocation f = _findIdentifier('f/*<int>*/').parent; |
| 13430 FunctionType ft = f.staticType; | 13363 FunctionType ft = f.staticInvokeType; |
| 13431 expect(ft.toString(), '(String) → List<int>'); | 13364 expect(ft.toString(), '(String) → List<int>'); |
| 13432 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); | 13365 expect('${ft.typeArguments}/${ft.typeParameters}', '[String, int]/[E, T]'); |
| 13433 | 13366 |
| 13434 SimpleIdentifier x = _findIdentifier('x'); | 13367 SimpleIdentifier x = _findIdentifier('x'); |
| 13435 expect(x.staticType, | 13368 expect(x.staticType, |
| 13436 typeProvider.listType.substitute4([typeProvider.intType])); | 13369 typeProvider.listType.substitute4([typeProvider.intType])); |
| 13437 } | 13370 } |
| 13438 | 13371 |
| 13372 void test_genericMethod_functionInvocation_explicit() { | |
| 13373 _resolveTestUnit(r''' | |
|
Jennifer Messerly
2016/01/06 22:25:51
BTW, I added a very similar version of this to che
| |
| 13374 class C<E> { | |
| 13375 /*=T*/ f/*<T>*/(/*=T*/ e) => null; | |
| 13376 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13377 static final h = g; | |
| 13378 } | |
| 13379 | |
| 13380 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13381 var topG = topF; | |
| 13382 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13383 var c = new C<int>(); | |
| 13384 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13385 var methodCall = c.f/*<int>*/(3); | |
| 13386 var staticCall = C.g/*<int>*/(3); | |
| 13387 var staticFieldCall = C.h/*<int>*/(3); | |
| 13388 var topFunCall = topF/*<int>*/(3); | |
| 13389 var topFieldCall = topG/*<int>*/(3); | |
| 13390 var localCall = lf/*<int>*/(3); | |
| 13391 var paramCall = pf/*<int>*/(3); | |
| 13392 } | |
| 13393 '''); | |
| 13394 expect(_findIdentifier('methodCall').staticType.toString(), "int"); | |
| 13395 expect(_findIdentifier('staticCall').staticType.toString(), "int"); | |
| 13396 expect(_findIdentifier('staticFieldCall').staticType.toString(), "int"); | |
| 13397 expect(_findIdentifier('topFunCall').staticType.toString(), "int"); | |
| 13398 expect(_findIdentifier('topFieldCall').staticType.toString(), "int"); | |
| 13399 expect(_findIdentifier('localCall').staticType.toString(), "int"); | |
| 13400 expect(_findIdentifier('paramCall').staticType.toString(), "int"); | |
| 13401 } | |
| 13402 | |
| 13439 void test_genericMethod_functionTypedParameter() { | 13403 void test_genericMethod_functionTypedParameter() { |
| 13440 _resolveTestUnit(r''' | 13404 _resolveTestUnit(r''' |
| 13441 class C<E> { | 13405 class C<E> { |
| 13442 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; | 13406 List/*<T>*/ f/*<T>*/(/*=T*/ f(E e)) => null; |
| 13443 } | 13407 } |
| 13444 main() { | 13408 main() { |
| 13445 C<String> cOfString; | 13409 C<String> cOfString; |
| 13446 } | 13410 } |
| 13447 '''); | 13411 '''); |
| 13448 SimpleIdentifier f = _findIdentifier('f'); | 13412 SimpleIdentifier f = _findIdentifier('f'); |
| 13449 MethodElementImpl e = f.staticElement; | 13413 MethodElementImpl e = f.staticElement; |
| 13450 expect(e.typeParameters.toString(), '[T]'); | 13414 expect(e.typeParameters.toString(), '[T]'); |
| 13451 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13415 expect(e.type.typeFormals.toString(), '[T]'); |
| 13452 expect(e.type.typeParameters.toString(), '[E]'); | 13416 expect(e.type.typeParameters.toString(), '[E]'); |
| 13453 expect(e.type.typeArguments.toString(), '[E]'); | 13417 expect(e.type.typeArguments.toString(), '[E]'); |
| 13454 expect(e.type.toString(), '<T>((E) → T) → List<T>'); | 13418 expect(e.type.toString(), '<T>((E) → T) → List<T>'); |
| 13455 | 13419 |
| 13456 SimpleIdentifier c = _findIdentifier('cOfString'); | 13420 SimpleIdentifier c = _findIdentifier('cOfString'); |
| 13457 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; | 13421 FunctionType ft = (c.staticType as InterfaceType).getMethod('f').type; |
| 13458 expect(ft.toString(), '<T>((String) → T) → List<T>'); | 13422 expect(ft.toString(), '<T>((String) → T) → List<T>'); |
| 13459 ft = ft.instantiate([typeProvider.intType]); | 13423 ft = ft.instantiate([typeProvider.intType]); |
| 13460 expect(ft.toString(), '((String) → int) → List<int>'); | 13424 expect(ft.toString(), '((String) → int) → List<int>'); |
| 13461 } | 13425 } |
| 13462 | 13426 |
| 13463 void test_genericMethod_implicitDynamic() { | 13427 void test_genericMethod_implicitDynamic() { |
| 13464 // Regression test for: | 13428 // Regression test for: |
| 13465 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 | 13429 // https://github.com/dart-lang/sdk/issues/25100#issuecomment-162047588 |
| 13466 // These should not cause any hints or warnings. | 13430 // These should not cause any hints or warnings. |
| 13467 _resolveTestUnit(r''' | 13431 _resolveTestUnit(r''' |
| 13468 class List<E> { | 13432 class List<E> { |
| 13469 /*=T*/ map/*<T>*/(/*=T*/ f(E e)) => null; | 13433 /*=T*/ map/*<T>*/(/*=T*/ f(E e)) => null; |
| 13470 } | 13434 } |
| 13471 void foo() { | 13435 void foo() { |
| 13472 List list = null; | 13436 List list = null; |
| 13473 list.map((e) => e); | 13437 list.map((e) => e); |
| 13474 list.map((e) => 3); | 13438 list.map((e) => 3); |
| 13475 }'''); | 13439 }'''); |
| 13476 | 13440 |
| 13477 SimpleIdentifier map1 = _findIdentifier('map((e) => e);'); | 13441 SimpleIdentifier map1 = _findIdentifier('map((e) => e);'); |
| 13478 expect(map1.staticType.toString(), '((dynamic) → dynamic) → dynamic'); | 13442 MethodInvocation m1 = map1.parent; |
| 13443 expect(m1.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); | |
| 13444 expect(map1.staticType, isNull); | |
| 13479 expect(map1.propagatedType, isNull); | 13445 expect(map1.propagatedType, isNull); |
| 13480 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); | 13446 SimpleIdentifier map2 = _findIdentifier('map((e) => 3);'); |
| 13481 expect(map2.staticType.toString(), '((dynamic) → int) → int'); | 13447 MethodInvocation m2 = map2.parent; |
| 13448 expect(m2.staticInvokeType.toString(), '((dynamic) → int) → int'); | |
| 13449 expect(map2.staticType, isNull); | |
| 13482 expect(map2.propagatedType, isNull); | 13450 expect(map2.propagatedType, isNull); |
| 13483 } | 13451 } |
| 13484 | 13452 |
| 13485 void test_genericMethod_nestedCapture() { | 13453 void test_genericMethod_nestedCapture() { |
| 13486 _resolveTestUnit(r''' | 13454 _resolveTestUnit(r''' |
| 13487 class C<T> { | 13455 class C<T> { |
| 13488 /*=T*/ f/*<S>*/(/*=S*/ x) { | 13456 /*=T*/ f/*<S>*/(/*=S*/ x) { |
| 13489 new C<S>().f/*<int>*/(3); | 13457 new C<S>().f/*<int>*/(3); |
| 13490 new C<S>().f; // tear-off | 13458 new C<S>().f; // tear-off |
| 13491 return null; | 13459 return null; |
| 13492 } | 13460 } |
| 13493 } | 13461 } |
| 13494 '''); | 13462 '''); |
| 13495 SimpleIdentifier f = _findIdentifier('f/*<int>*/(3);'); | 13463 MethodInvocation f = _findIdentifier('f/*<int>*/(3);').parent; |
| 13496 expect(f.staticType.toString(), '(int) → S'); | 13464 expect(f.staticInvokeType.toString(), '(int) → S'); |
| 13497 FunctionType ft = f.staticType; | 13465 FunctionType ft = f.staticInvokeType; |
| 13498 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); | 13466 expect('${ft.typeArguments}/${ft.typeParameters}', '[S, int]/[T, S]'); |
| 13499 | 13467 |
| 13500 f = _findIdentifier('f;'); | 13468 SimpleIdentifier f2 = _findIdentifier('f;'); |
| 13501 expect(f.staticType.toString(), '<S₀>(S₀) → S'); | 13469 expect(f2.staticType.toString(), '<S₀>(S₀) → S'); |
| 13502 } | 13470 } |
| 13503 | 13471 |
| 13504 void test_genericMethod_nestedFunctions() { | 13472 void test_genericMethod_nestedFunctions() { |
| 13505 _resolveTestUnit(r''' | 13473 _resolveTestUnit(r''' |
| 13506 /*=S*/ f/*<S>*/(/*=S*/ x) { | 13474 /*=S*/ f/*<S>*/(/*=S*/ x) { |
| 13507 g/*<S>*/(/*=S*/ x) => f; | 13475 g/*<S>*/(/*=S*/ x) => f; |
| 13508 return null; | 13476 return null; |
| 13509 } | 13477 } |
| 13510 '''); | 13478 '''); |
| 13511 SimpleIdentifier g = _findIdentifier('f'); | 13479 SimpleIdentifier g = _findIdentifier('f'); |
| 13512 expect(g.staticType.toString(), '<S>(S) → S'); | 13480 expect(g.staticType.toString(), '<S>(S) → S'); |
| 13513 SimpleIdentifier f = _findIdentifier('g'); | 13481 SimpleIdentifier f = _findIdentifier('g'); |
| 13514 expect(f.staticType.toString(), '<S>(S) → dynamic'); | 13482 expect(f.staticType.toString(), '<S>(S) → dynamic'); |
| 13515 } | 13483 } |
| 13516 | 13484 |
| 13517 void test_genericMethod_override() { | 13485 void test_genericMethod_override() { |
| 13518 _resolveTestUnit(r''' | 13486 _resolveTestUnit(r''' |
| 13519 class C { | 13487 class C { |
| 13520 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 13488 /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 13521 } | 13489 } |
| 13522 class D extends C { | 13490 class D extends C { |
| 13523 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D | 13491 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D |
| 13524 } | 13492 } |
| 13525 '''); | 13493 '''); |
| 13526 SimpleIdentifier f = | 13494 SimpleIdentifier f = |
| 13527 _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); | 13495 _findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); |
| 13528 MethodElementImpl e = f.staticElement; | 13496 MethodElementImpl e = f.staticElement; |
| 13529 expect(e.typeParameters.toString(), '[T]'); | 13497 expect(e.typeParameters.toString(), '[T]'); |
| 13530 expect(e.type.boundTypeParameters.toString(), '[T]'); | 13498 expect(e.type.typeFormals.toString(), '[T]'); |
| 13531 expect(e.type.toString(), '<T>(T) → T'); | 13499 expect(e.type.toString(), '<T>(T) → T'); |
| 13532 | 13500 |
| 13533 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 13501 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 13534 expect(ft.toString(), '(String) → String'); | 13502 expect(ft.toString(), '(String) → String'); |
| 13535 } | 13503 } |
| 13536 | 13504 |
| 13537 void test_genericMethod_override_bounds() { | 13505 void test_genericMethod_override_bounds() { |
| 13538 _resolveTestUnit(r''' | 13506 _resolveTestUnit(r''' |
| 13539 class A {} | 13507 class A {} |
| 13540 class B extends A {} | 13508 class B extends A {} |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13599 // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors | 13567 // TODO(jmesserly): we can't use assertErrors because STRONG_MODE_* errors |
| 13600 // from CodeChecker don't have working equality. | 13568 // from CodeChecker don't have working equality. |
| 13601 List<AnalysisError> errors = analysisContext2.computeErrors(source); | 13569 List<AnalysisError> errors = analysisContext2.computeErrors(source); |
| 13602 expect(errors.map((e) => e.errorCode.name), [ | 13570 expect(errors.map((e) => e.errorCode.name), [ |
| 13603 'STRONG_MODE_INVALID_METHOD_OVERRIDE', | 13571 'STRONG_MODE_INVALID_METHOD_OVERRIDE', |
| 13604 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' | 13572 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS' |
| 13605 ]); | 13573 ]); |
| 13606 verify([source]); | 13574 verify([source]); |
| 13607 } | 13575 } |
| 13608 | 13576 |
| 13577 void test_genericMethod_tearoff() { | |
|
Jennifer Messerly
2016/01/06 22:25:51
nothing changed here just sorting
| |
| 13578 _resolveTestUnit(r''' | |
| 13579 class C<E> { | |
| 13580 /*=T*/ f/*<T>*/(E e) => null; | |
| 13581 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | |
| 13582 static final h = g; | |
| 13583 } | |
| 13584 | |
| 13585 /*=T*/ topF/*<T>*/(/*=T*/ e) => null; | |
| 13586 var topG = topF; | |
| 13587 void test/*<S>*/(/*=T*/ pf/*<T>*/(/*=T*/ e)) { | |
| 13588 var c = new C<int>(); | |
| 13589 /*=T*/ lf/*<T>*/(/*=T*/ e) => null; | |
| 13590 var methodTearOff = c.f; | |
| 13591 var staticTearOff = C.g; | |
| 13592 var staticFieldTearOff = C.h; | |
| 13593 var topFunTearOff = topF; | |
| 13594 var topFieldTearOff = topG; | |
| 13595 var localTearOff = lf; | |
| 13596 var paramTearOff = pf; | |
| 13597 } | |
| 13598 '''); | |
| 13599 expect( | |
| 13600 _findIdentifier('methodTearOff').staticType.toString(), "<T>(int) → T"); | |
| 13601 expect( | |
| 13602 _findIdentifier('staticTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13603 expect(_findIdentifier('staticFieldTearOff').staticType.toString(), | |
| 13604 "<T>(T) → T"); | |
| 13605 expect( | |
| 13606 _findIdentifier('topFunTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13607 expect( | |
| 13608 _findIdentifier('topFieldTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13609 expect(_findIdentifier('localTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13610 expect(_findIdentifier('paramTearOff').staticType.toString(), "<T>(T) → T"); | |
| 13611 } | |
| 13612 | |
| 13609 void test_pseudoGeneric_max_doubleDouble() { | 13613 void test_pseudoGeneric_max_doubleDouble() { |
| 13610 String code = r''' | 13614 String code = r''' |
| 13611 import 'dart:math'; | 13615 import 'dart:math'; |
| 13612 main() { | 13616 main() { |
| 13613 var foo = max(1.0, 2.0); | 13617 var foo = max(1.0, 2.0); |
| 13614 } | 13618 } |
| 13615 '''; | 13619 '''; |
| 13616 _resolveTestUnit(code); | 13620 _resolveTestUnit(code); |
| 13617 | 13621 |
| 13618 SimpleIdentifier identifier = _findIdentifier('foo'); | 13622 SimpleIdentifier identifier = _findIdentifier('foo'); |
| (...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16594 | 16598 |
| 16595 void _resolveTestUnit(String code) { | 16599 void _resolveTestUnit(String code) { |
| 16596 testCode = code; | 16600 testCode = code; |
| 16597 testSource = addSource(testCode); | 16601 testSource = addSource(testCode); |
| 16598 LibraryElement library = resolve2(testSource); | 16602 LibraryElement library = resolve2(testSource); |
| 16599 assertNoErrors(testSource); | 16603 assertNoErrors(testSource); |
| 16600 verify([testSource]); | 16604 verify([testSource]); |
| 16601 testUnit = resolveCompilationUnit(testSource, library); | 16605 testUnit = resolveCompilationUnit(testSource, library); |
| 16602 } | 16606 } |
| 16603 } | 16607 } |
| OLD | NEW |