| 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 6248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6259 MemberMap map = new MemberMap(); | 6259 MemberMap map = new MemberMap(); |
| 6260 expect(map.size, 0); | 6260 expect(map.size, 0); |
| 6261 map.put(m1.name, m1); | 6261 map.put(m1.name, m1); |
| 6262 expect(map.size, 1); | 6262 expect(map.size, 1); |
| 6263 expect(map.get("m1"), m1); | 6263 expect(map.get("m1"), m1); |
| 6264 } | 6264 } |
| 6265 } | 6265 } |
| 6266 | 6266 |
| 6267 @reflectiveTest | 6267 @reflectiveTest |
| 6268 class NonHintCodeTest extends ResolverTestCase { | 6268 class NonHintCodeTest extends ResolverTestCase { |
| 6269 void fail_propagatedFieldType() { | |
| 6270 // From dartbug.com/20019 | |
| 6271 Source source = addSource(r''' | |
| 6272 class A { } | |
| 6273 class X<T> { | |
| 6274 final x = new List<T>(); | |
| 6275 } | |
| 6276 class Z { | |
| 6277 final X<A> y = new X<A>(); | |
| 6278 foo() { | |
| 6279 y.x.add(new A()); | |
| 6280 } | |
| 6281 }'''); | |
| 6282 resolve(source); | |
| 6283 assertNoErrors(source); | |
| 6284 verify([source]); | |
| 6285 } | |
| 6286 | |
| 6287 void test_deadCode_deadBlock_conditionalElse_debugConst() { | 6269 void test_deadCode_deadBlock_conditionalElse_debugConst() { |
| 6288 Source source = addSource(r''' | 6270 Source source = addSource(r''' |
| 6289 const bool DEBUG = true; | 6271 const bool DEBUG = true; |
| 6290 f() { | 6272 f() { |
| 6291 DEBUG ? 1 : 2; | 6273 DEBUG ? 1 : 2; |
| 6292 }'''); | 6274 }'''); |
| 6293 resolve(source); | 6275 resolve(source); |
| 6294 assertNoErrors(source); | 6276 assertNoErrors(source); |
| 6295 verify([source]); | 6277 verify([source]); |
| 6296 } | 6278 } |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6705 } | 6687 } |
| 6706 class B extends A { | 6688 class B extends A { |
| 6707 @override | 6689 @override |
| 6708 set m(int x) {} | 6690 set m(int x) {} |
| 6709 }'''); | 6691 }'''); |
| 6710 resolve(source); | 6692 resolve(source); |
| 6711 assertNoErrors(source); | 6693 assertNoErrors(source); |
| 6712 verify([source]); | 6694 verify([source]); |
| 6713 } | 6695 } |
| 6714 | 6696 |
| 6697 void test_propagatedFieldType() { |
| 6698 Source source = addSource(r''' |
| 6699 class A { } |
| 6700 class X<T> { |
| 6701 final x = new List<T>(); |
| 6702 } |
| 6703 class Z { |
| 6704 final X<A> y = new X<A>(); |
| 6705 foo() { |
| 6706 y.x.add(new A()); |
| 6707 } |
| 6708 }'''); |
| 6709 resolve(source); |
| 6710 assertNoErrors(source); |
| 6711 verify([source]); |
| 6712 } |
| 6713 |
| 6715 void test_proxy_annotation_prefixed() { | 6714 void test_proxy_annotation_prefixed() { |
| 6716 Source source = addSource(r''' | 6715 Source source = addSource(r''' |
| 6717 library L; | 6716 library L; |
| 6718 @proxy | 6717 @proxy |
| 6719 class A {} | 6718 class A {} |
| 6720 f(var a) { | 6719 f(var a) { |
| 6721 a = new A(); | 6720 a = new A(); |
| 6722 a.m(); | 6721 a.m(); |
| 6723 var x = a.g; | 6722 var x = a.g; |
| 6724 a.s = 1; | 6723 a.s = 1; |
| (...skipping 5261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11986 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 11985 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 11987 BlockFunctionBody body = | 11986 BlockFunctionBody body = |
| 11988 function.functionExpression.body as BlockFunctionBody; | 11987 function.functionExpression.body as BlockFunctionBody; |
| 11989 ExpressionStatement statement = | 11988 ExpressionStatement statement = |
| 11990 body.block.statements[1] as ExpressionStatement; | 11989 body.block.statements[1] as ExpressionStatement; |
| 11991 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; | 11990 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| 11992 SimpleIdentifier variableName = invocation.prefix; | 11991 SimpleIdentifier variableName = invocation.prefix; |
| 11993 expect(variableName.propagatedType, same(typeProvider.stringType)); | 11992 expect(variableName.propagatedType, same(typeProvider.stringType)); |
| 11994 } | 11993 } |
| 11995 | 11994 |
| 11995 void test_initializer_hasStaticType() { |
| 11996 Source source = addSource(r''' |
| 11997 f() { |
| 11998 int v = 0; |
| 11999 return v; |
| 12000 }'''); |
| 12001 LibraryElement library = resolve(source); |
| 12002 assertNoErrors(source); |
| 12003 verify([source]); |
| 12004 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12005 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12006 BlockFunctionBody body = |
| 12007 function.functionExpression.body as BlockFunctionBody; |
| 12008 NodeList<Statement> statements = body.block.statements; |
| 12009 // Type of 'v' in declaration. |
| 12010 { |
| 12011 VariableDeclarationStatement statement = |
| 12012 statements[0] as VariableDeclarationStatement; |
| 12013 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 12014 expect(variableName.staticType, same(typeProvider.intType)); |
| 12015 expect(variableName.propagatedType, isNull); |
| 12016 } |
| 12017 // Type of 'v' in reference. |
| 12018 { |
| 12019 ReturnStatement statement = statements[1] as ReturnStatement; |
| 12020 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12021 expect(variableName.staticType, same(typeProvider.intType)); |
| 12022 expect(variableName.propagatedType, isNull); |
| 12023 } |
| 12024 } |
| 12025 |
| 12026 void test_initializer_hasStaticType_parameterized() { |
| 12027 Source source = addSource(r''' |
| 12028 f() { |
| 12029 List<int> v = <int>[]; |
| 12030 return v; |
| 12031 }'''); |
| 12032 LibraryElement library = resolve(source); |
| 12033 assertNoErrors(source); |
| 12034 verify([source]); |
| 12035 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12036 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12037 BlockFunctionBody body = |
| 12038 function.functionExpression.body as BlockFunctionBody; |
| 12039 NodeList<Statement> statements = body.block.statements; |
| 12040 // Type of 'v' in declaration. |
| 12041 { |
| 12042 VariableDeclarationStatement statement = |
| 12043 statements[0] as VariableDeclarationStatement; |
| 12044 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 12045 expect(variableName.staticType, isNotNull); |
| 12046 expect(variableName.propagatedType, isNull); |
| 12047 } |
| 12048 // Type of 'v' in reference. |
| 12049 { |
| 12050 ReturnStatement statement = statements[1] as ReturnStatement; |
| 12051 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12052 expect(variableName.staticType, isNotNull); |
| 12053 expect(variableName.propagatedType, isNull); |
| 12054 } |
| 12055 } |
| 12056 |
| 11996 void test_initializer_null() { | 12057 void test_initializer_null() { |
| 11997 String code = r''' | 12058 String code = r''' |
| 11998 main() { | 12059 main() { |
| 11999 int v = null; | 12060 int v = null; |
| 12000 return v; // marker | 12061 return v; // marker |
| 12001 }'''; | 12062 }'''; |
| 12002 CompilationUnit unit; | 12063 CompilationUnit unit; |
| 12003 { | 12064 { |
| 12004 Source source = addSource(code); | 12065 Source source = addSource(code); |
| 12005 LibraryElement library = resolve(source); | 12066 LibraryElement library = resolve(source); |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13400 // check propagated type | 13461 // check propagated type |
| 13401 FunctionType propagatedType = node.propagatedType as FunctionType; | 13462 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13402 expect(propagatedType.returnType, test.typeProvider.stringType); | 13463 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13403 } on AnalysisException catch (e, stackTrace) { | 13464 } on AnalysisException catch (e, stackTrace) { |
| 13404 thrownException[0] = new CaughtException(e, stackTrace); | 13465 thrownException[0] = new CaughtException(e, stackTrace); |
| 13405 } | 13466 } |
| 13406 } | 13467 } |
| 13407 return null; | 13468 return null; |
| 13408 } | 13469 } |
| 13409 } | 13470 } |
| OLD | NEW |