| 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 void test_getType_noScope() { | 939 void test_getType_noScope() { |
| 940 TypeOverrideManager manager = new TypeOverrideManager(); | 940 TypeOverrideManager manager = new TypeOverrideManager(); |
| 941 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); | 941 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 942 } | 942 } |
| 943 } | 943 } |
| 944 | 944 |
| 945 @reflectiveTest | 945 @reflectiveTest |
| 946 class TypePropagationTest extends ResolverTestCase { | 946 class TypePropagationTest extends ResolverTestCase { |
| 947 fail_mergePropagatedTypesAtJoinPoint_1() async { | 947 fail_mergePropagatedTypesAtJoinPoint_1() async { |
| 948 // https://code.google.com/p/dart/issues/detail?id=19929 | 948 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 949 await assertTypeOfMarkedExpression( | 949 var code = r''' |
| 950 r''' | |
| 951 f1(x) { | 950 f1(x) { |
| 952 var y = []; | 951 var y = []; |
| 953 if (x) { | 952 if (x) { |
| 954 y = 0; | 953 y = 0; |
| 955 } else { | 954 } else { |
| 956 y = ''; | 955 y = ''; |
| 957 } | 956 } |
| 958 // Propagated type is [List] here: incorrect. | 957 // Propagated type is [List] here: incorrect. |
| 959 // Best we can do is [Object]? | 958 // Best we can do is [Object]? |
| 960 return y; // marker | 959 return y; // marker |
| 961 }''', | 960 }'''; |
| 962 null, | 961 CompilationUnit unit = await resolveSource(code); |
| 963 typeProvider.dynamicType); | 962 assertTypeOfMarkedExpression(code, unit, null, typeProvider.dynamicType); |
| 964 } | 963 } |
| 965 | 964 |
| 966 fail_mergePropagatedTypesAtJoinPoint_2() async { | 965 fail_mergePropagatedTypesAtJoinPoint_2() async { |
| 967 // https://code.google.com/p/dart/issues/detail?id=19929 | 966 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 968 await assertTypeOfMarkedExpression( | 967 var code = r''' |
| 969 r''' | |
| 970 f2(x) { | 968 f2(x) { |
| 971 var y = []; | 969 var y = []; |
| 972 if (x) { | 970 if (x) { |
| 973 y = 0; | 971 y = 0; |
| 974 } else { | 972 } else { |
| 975 } | 973 } |
| 976 // Propagated type is [List] here: incorrect. | 974 // Propagated type is [List] here: incorrect. |
| 977 // Best we can do is [Object]? | 975 // Best we can do is [Object]? |
| 978 return y; // marker | 976 return y; // marker |
| 979 }''', | 977 }'''; |
| 980 null, | 978 CompilationUnit unit = await resolveSource(code); |
| 981 typeProvider.dynamicType); | 979 assertTypeOfMarkedExpression(code, unit, null, typeProvider.dynamicType); |
| 982 } | 980 } |
| 983 | 981 |
| 984 fail_mergePropagatedTypesAtJoinPoint_3() async { | 982 fail_mergePropagatedTypesAtJoinPoint_3() async { |
| 985 // https://code.google.com/p/dart/issues/detail?id=19929 | 983 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 986 await assertTypeOfMarkedExpression( | 984 var code = r''' |
| 987 r''' | |
| 988 f4(x) { | 985 f4(x) { |
| 989 var y = []; | 986 var y = []; |
| 990 if (x) { | 987 if (x) { |
| 991 y = 0; | 988 y = 0; |
| 992 } else { | 989 } else { |
| 993 y = 1.5; | 990 y = 1.5; |
| 994 } | 991 } |
| 995 // Propagated type is [List] here: incorrect. | 992 // Propagated type is [List] here: incorrect. |
| 996 // A correct answer is the least upper bound of [int] and [double], | 993 // A correct answer is the least upper bound of [int] and [double], |
| 997 // i.e. [num]. | 994 // i.e. [num]. |
| 998 return y; // marker | 995 return y; // marker |
| 999 }''', | 996 }'''; |
| 1000 null, | 997 CompilationUnit unit = await resolveSource(code); |
| 1001 typeProvider.numType); | 998 assertTypeOfMarkedExpression(code, unit, null, typeProvider.numType); |
| 1002 } | 999 } |
| 1003 | 1000 |
| 1004 fail_mergePropagatedTypesAtJoinPoint_5() async { | 1001 fail_mergePropagatedTypesAtJoinPoint_5() async { |
| 1005 // https://code.google.com/p/dart/issues/detail?id=19929 | 1002 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 1006 await assertTypeOfMarkedExpression( | 1003 var code = r''' |
| 1007 r''' | |
| 1008 f6(x,y) { | 1004 f6(x,y) { |
| 1009 var z = []; | 1005 var z = []; |
| 1010 if (x || (z = y) < 0) { | 1006 if (x || (z = y) < 0) { |
| 1011 } else { | 1007 } else { |
| 1012 z = 0; | 1008 z = 0; |
| 1013 } | 1009 } |
| 1014 // Propagated type is [List] here: incorrect. | 1010 // Propagated type is [List] here: incorrect. |
| 1015 // Best we can do is [Object]? | 1011 // Best we can do is [Object]? |
| 1016 return z; // marker | 1012 return z; // marker |
| 1017 }''', | 1013 }'''; |
| 1018 null, | 1014 CompilationUnit unit = await resolveSource(code); |
| 1019 typeProvider.dynamicType); | 1015 assertTypeOfMarkedExpression(code, unit, null, typeProvider.dynamicType); |
| 1020 } | 1016 } |
| 1021 | 1017 |
| 1022 fail_mergePropagatedTypesAtJoinPoint_7() async { | 1018 fail_mergePropagatedTypesAtJoinPoint_7() async { |
| 1023 // https://code.google.com/p/dart/issues/detail?id=19929 | 1019 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 1024 // | 1020 // |
| 1025 // In general [continue]s are unsafe for the purposes of | 1021 // In general [continue]s are unsafe for the purposes of |
| 1026 // [isAbruptTerminationStatement]. | 1022 // [isAbruptTerminationStatement]. |
| 1027 // | 1023 // |
| 1028 // This is like example 6, but less tricky: the code in the branch that | 1024 // This is like example 6, but less tricky: the code in the branch that |
| 1029 // [continue]s is in effect after the [if]. | 1025 // [continue]s is in effect after the [if]. |
| 1030 String code = r''' | 1026 String code = r''' |
| 1031 f() { | 1027 f() { |
| 1032 var x = 0; | 1028 var x = 0; |
| 1033 var c = false; | 1029 var c = false; |
| 1034 var d = true; | 1030 var d = true; |
| 1035 while (d) { | 1031 while (d) { |
| 1036 if (c) { | 1032 if (c) { |
| 1037 d = false; | 1033 d = false; |
| 1038 } else { | 1034 } else { |
| 1039 x = ''; | 1035 x = ''; |
| 1040 c = true; | 1036 c = true; |
| 1041 continue; | 1037 continue; |
| 1042 } | 1038 } |
| 1043 x; // marker | 1039 x; // marker |
| 1044 } | 1040 } |
| 1045 }'''; | 1041 }'''; |
| 1042 CompilationUnit unit = await resolveSource(code); |
| 1046 DartType t = | 1043 DartType t = |
| 1047 (await findMarkedIdentifier(code, "; // marker")).propagatedType; | 1044 findMarkedIdentifier(code, unit, "; // marker").propagatedType; |
| 1048 expect(typeProvider.intType.isSubtypeOf(t), isTrue); | 1045 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 1049 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); | 1046 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 1050 } | 1047 } |
| 1051 | 1048 |
| 1052 fail_mergePropagatedTypesAtJoinPoint_8() async { | 1049 fail_mergePropagatedTypesAtJoinPoint_8() async { |
| 1053 // https://code.google.com/p/dart/issues/detail?id=19929 | 1050 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 1054 // | 1051 // |
| 1055 // In nested loops [breaks]s are unsafe for the purposes of | 1052 // In nested loops [breaks]s are unsafe for the purposes of |
| 1056 // [isAbruptTerminationStatement]. | 1053 // [isAbruptTerminationStatement]. |
| 1057 // | 1054 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1069 d = false; | 1066 d = false; |
| 1070 } else { | 1067 } else { |
| 1071 x = ''; | 1068 x = ''; |
| 1072 c = true; | 1069 c = true; |
| 1073 break; | 1070 break; |
| 1074 } | 1071 } |
| 1075 x; // marker | 1072 x; // marker |
| 1076 } | 1073 } |
| 1077 } | 1074 } |
| 1078 }'''; | 1075 }'''; |
| 1076 CompilationUnit unit = await resolveSource(code); |
| 1079 DartType t = | 1077 DartType t = |
| 1080 (await findMarkedIdentifier(code, "; // marker")).propagatedType; | 1078 findMarkedIdentifier(code, unit, "; // marker").propagatedType; |
| 1081 expect(typeProvider.intType.isSubtypeOf(t), isTrue); | 1079 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 1082 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); | 1080 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 1083 } | 1081 } |
| 1084 | 1082 |
| 1085 fail_propagatedReturnType_functionExpression() async { | 1083 fail_propagatedReturnType_functionExpression() async { |
| 1086 // TODO(scheglov) disabled because we don't resolve function expression | 1084 // TODO(scheglov) disabled because we don't resolve function expression |
| 1087 String code = r''' | 1085 String code = r''' |
| 1088 main() { | 1086 main() { |
| 1089 var v = (() {return 42;})(); | 1087 var v = (() {return 42;})(); |
| 1090 }'''; | 1088 }'''; |
| 1091 await assertPropagatedAssignedType( | 1089 CompilationUnit unit = await resolveSource(code); |
| 1092 code, typeProvider.dynamicType, typeProvider.intType); | 1090 assertPropagatedAssignedType( |
| 1091 code, unit, typeProvider.dynamicType, typeProvider.intType); |
| 1093 } | 1092 } |
| 1094 | 1093 |
| 1095 test_as() async { | 1094 test_as() async { |
| 1096 Source source = addSource(r''' | 1095 Source source = addSource(r''' |
| 1097 class A { | 1096 class A { |
| 1098 bool get g => true; | 1097 bool get g => true; |
| 1099 } | 1098 } |
| 1100 A f(var p) { | 1099 A f(var p) { |
| 1101 if ((p as A).g) { | 1100 if ((p as A).g) { |
| 1102 return p; | 1101 return p; |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 '/helper.dart', | 1620 '/helper.dart', |
| 1622 ''' | 1621 ''' |
| 1623 library helper; | 1622 library helper; |
| 1624 int max(int x, int y) => 0; | 1623 int max(int x, int y) => 0; |
| 1625 '''); | 1624 '''); |
| 1626 String code = ''' | 1625 String code = ''' |
| 1627 import 'helper.dart' as helper; | 1626 import 'helper.dart' as helper; |
| 1628 main() { | 1627 main() { |
| 1629 helper.max(10, 10); // marker | 1628 helper.max(10, 10); // marker |
| 1630 }'''; | 1629 }'''; |
| 1630 CompilationUnit unit = await resolveSource(code); |
| 1631 SimpleIdentifier methodName = | 1631 SimpleIdentifier methodName = |
| 1632 await findMarkedIdentifier(code, "(10, 10); // marker"); | 1632 findMarkedIdentifier(code, unit, "(10, 10); // marker"); |
| 1633 MethodInvocation methodInvoke = methodName.parent; | 1633 MethodInvocation methodInvoke = methodName.parent; |
| 1634 expect(methodInvoke.methodName.staticElement, isNotNull); | 1634 expect(methodInvoke.methodName.staticElement, isNotNull); |
| 1635 expect(methodInvoke.methodName.propagatedElement, isNull); | 1635 expect(methodInvoke.methodName.propagatedElement, isNull); |
| 1636 } | 1636 } |
| 1637 | 1637 |
| 1638 test_is_conditional() async { | 1638 test_is_conditional() async { |
| 1639 Source source = addSource(r''' | 1639 Source source = addSource(r''' |
| 1640 class A {} | 1640 class A {} |
| 1641 A f(var p) { | 1641 A f(var p) { |
| 1642 return (p is A) ? p : null; | 1642 return (p is A) ? p : null; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 class A {} | 1959 class A {} |
| 1960 class B extends A {} | 1960 class B extends A {} |
| 1961 f() { | 1961 f() { |
| 1962 var a = new A(); | 1962 var a = new A(); |
| 1963 var b = new B(); | 1963 var b = new B(); |
| 1964 b; // B | 1964 b; // B |
| 1965 if (a is B) { | 1965 if (a is B) { |
| 1966 return a; // marker | 1966 return a; // marker |
| 1967 } | 1967 } |
| 1968 }'''; | 1968 }'''; |
| 1969 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType; | 1969 CompilationUnit unit = await resolveSource(code); |
| 1970 await assertTypeOfMarkedExpression(code, null, tB); | 1970 DartType tB = findMarkedIdentifier(code, unit, "; // B").propagatedType; |
| 1971 assertTypeOfMarkedExpression(code, unit, null, tB); |
| 1971 } | 1972 } |
| 1972 | 1973 |
| 1973 test_issue20904BuggyTypePromotionAtIfJoin_6() async { | 1974 test_issue20904BuggyTypePromotionAtIfJoin_6() async { |
| 1974 // https://code.google.com/p/dart/issues/detail?id=20904 | 1975 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 1975 // | 1976 // |
| 1976 // The other half of the *_5() test. | 1977 // The other half of the *_5() test. |
| 1977 // | 1978 // |
| 1978 // Here the is-check loses precision, so we don't use it. | 1979 // Here the is-check loses precision, so we don't use it. |
| 1979 String code = r''' | 1980 String code = r''' |
| 1980 class A {} | 1981 class A {} |
| 1981 class B extends A {} | 1982 class B extends A {} |
| 1982 f() { | 1983 f() { |
| 1983 var b = new B(); | 1984 var b = new B(); |
| 1984 b; // B | 1985 b; // B |
| 1985 if (b is A) { | 1986 if (b is A) { |
| 1986 return b; // marker | 1987 return b; // marker |
| 1987 } | 1988 } |
| 1988 }'''; | 1989 }'''; |
| 1989 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType; | 1990 CompilationUnit unit = await resolveSource(code); |
| 1990 await assertTypeOfMarkedExpression(code, null, tB); | 1991 DartType tB = findMarkedIdentifier(code, unit, "; // B").propagatedType; |
| 1992 assertTypeOfMarkedExpression(code, unit, null, tB); |
| 1991 } | 1993 } |
| 1992 | 1994 |
| 1993 test_listLiteral_different() async { | 1995 test_listLiteral_different() async { |
| 1994 Source source = addSource(r''' | 1996 Source source = addSource(r''' |
| 1995 f() { | 1997 f() { |
| 1996 var v = [0, '1', 2]; | 1998 var v = [0, '1', 2]; |
| 1997 return v[2]; | 1999 return v[2]; |
| 1998 }'''); | 2000 }'''); |
| 1999 CompilationUnit unit = await _computeResolvedUnit(source); | 2001 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2000 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 2002 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 | 2070 |
| 2069 test_mergePropagatedTypes_afterIfThen_different() async { | 2071 test_mergePropagatedTypes_afterIfThen_different() async { |
| 2070 String code = r''' | 2072 String code = r''' |
| 2071 main() { | 2073 main() { |
| 2072 var v = 0; | 2074 var v = 0; |
| 2073 if (v != null) { | 2075 if (v != null) { |
| 2074 v = ''; | 2076 v = ''; |
| 2075 } | 2077 } |
| 2076 return v; | 2078 return v; |
| 2077 }'''; | 2079 }'''; |
| 2080 CompilationUnit unit = await resolveSource(code); |
| 2078 { | 2081 { |
| 2079 SimpleIdentifier identifier = await findMarkedIdentifier(code, "v;"); | 2082 SimpleIdentifier identifier = findMarkedIdentifier(code, unit, "v;"); |
| 2080 expect(identifier.propagatedType, null); | 2083 expect(identifier.propagatedType, null); |
| 2081 } | 2084 } |
| 2082 { | 2085 { |
| 2083 SimpleIdentifier identifier = await findMarkedIdentifier(code, "v = '';"); | 2086 SimpleIdentifier identifier = |
| 2087 findMarkedIdentifier(code, unit, "v = '';"); |
| 2084 expect(identifier.propagatedType, typeProvider.stringType); | 2088 expect(identifier.propagatedType, typeProvider.stringType); |
| 2085 } | 2089 } |
| 2086 } | 2090 } |
| 2087 | 2091 |
| 2088 test_mergePropagatedTypes_afterIfThen_same() async { | 2092 test_mergePropagatedTypes_afterIfThen_same() async { |
| 2089 await assertTypeOfMarkedExpression( | 2093 var code = r''' |
| 2090 r''' | |
| 2091 main() { | 2094 main() { |
| 2092 var v = 1; | 2095 var v = 1; |
| 2093 if (v != null) { | 2096 if (v != null) { |
| 2094 v = 2; | 2097 v = 2; |
| 2095 } | 2098 } |
| 2096 return v; // marker | 2099 return v; // marker |
| 2097 }''', | 2100 }'''; |
| 2098 null, | 2101 CompilationUnit unit = await resolveSource(code); |
| 2099 typeProvider.intType); | 2102 assertTypeOfMarkedExpression(code, unit, null, typeProvider.intType); |
| 2100 } | 2103 } |
| 2101 | 2104 |
| 2102 test_mergePropagatedTypes_afterIfThenElse_different() async { | 2105 test_mergePropagatedTypes_afterIfThenElse_different() async { |
| 2103 await assertTypeOfMarkedExpression( | 2106 var code = r''' |
| 2104 r''' | |
| 2105 main() { | 2107 main() { |
| 2106 var v = 1; | 2108 var v = 1; |
| 2107 if (v != null) { | 2109 if (v != null) { |
| 2108 v = 2; | 2110 v = 2; |
| 2109 } else { | 2111 } else { |
| 2110 v = '3'; | 2112 v = '3'; |
| 2111 } | 2113 } |
| 2112 return v; // marker | 2114 return v; // marker |
| 2113 }''', | 2115 }'''; |
| 2114 null, | 2116 CompilationUnit unit = await resolveSource(code); |
| 2115 null); | 2117 assertTypeOfMarkedExpression(code, unit, null, null); |
| 2116 } | 2118 } |
| 2117 | 2119 |
| 2118 test_mergePropagatedTypes_afterIfThenElse_same() async { | 2120 test_mergePropagatedTypes_afterIfThenElse_same() async { |
| 2119 await assertTypeOfMarkedExpression( | 2121 var code = r''' |
| 2120 r''' | |
| 2121 main() { | 2122 main() { |
| 2122 var v = 1; | 2123 var v = 1; |
| 2123 if (v != null) { | 2124 if (v != null) { |
| 2124 v = 2; | 2125 v = 2; |
| 2125 } else { | 2126 } else { |
| 2126 v = 3; | 2127 v = 3; |
| 2127 } | 2128 } |
| 2128 return v; // marker | 2129 return v; // marker |
| 2129 }''', | 2130 }'''; |
| 2130 null, | 2131 CompilationUnit unit = await resolveSource(code); |
| 2131 typeProvider.intType); | 2132 assertTypeOfMarkedExpression(code, unit, null, typeProvider.intType); |
| 2132 } | 2133 } |
| 2133 | 2134 |
| 2134 test_mergePropagatedTypesAtJoinPoint_4() async { | 2135 test_mergePropagatedTypesAtJoinPoint_4() async { |
| 2135 // https://code.google.com/p/dart/issues/detail?id=19929 | 2136 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 2136 await assertTypeOfMarkedExpression( | 2137 var code = r''' |
| 2137 r''' | |
| 2138 f5(x) { | 2138 f5(x) { |
| 2139 var y = []; | 2139 var y = []; |
| 2140 if (x) { | 2140 if (x) { |
| 2141 y = 0; | 2141 y = 0; |
| 2142 } else { | 2142 } else { |
| 2143 return y; | 2143 return y; |
| 2144 } | 2144 } |
| 2145 // Propagated type is [int] here: correct. | 2145 // Propagated type is [int] here: correct. |
| 2146 return y; // marker | 2146 return y; // marker |
| 2147 }''', | 2147 }'''; |
| 2148 null, | 2148 CompilationUnit unit = await resolveSource(code); |
| 2149 typeProvider.intType); | 2149 assertTypeOfMarkedExpression(code, unit, null, typeProvider.intType); |
| 2150 } | 2150 } |
| 2151 | 2151 |
| 2152 test_mutatedOutsideScope() async { | 2152 test_mutatedOutsideScope() async { |
| 2153 // https://code.google.com/p/dart/issues/detail?id=22732 | 2153 // https://code.google.com/p/dart/issues/detail?id=22732 |
| 2154 Source source = addSource(r''' | 2154 Source source = addSource(r''' |
| 2155 class Base { | 2155 class Base { |
| 2156 } | 2156 } |
| 2157 | 2157 |
| 2158 class Derived extends Base { | 2158 class Derived extends Base { |
| 2159 get y => null; | 2159 get y => null; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2187 ''' | 2187 ''' |
| 2188 library helper; | 2188 library helper; |
| 2189 dynamic get $name => 42; | 2189 dynamic get $name => 42; |
| 2190 '''); | 2190 '''); |
| 2191 String code = ''' | 2191 String code = ''' |
| 2192 import 'helper.dart' as helper; | 2192 import 'helper.dart' as helper; |
| 2193 main() { | 2193 main() { |
| 2194 helper.$name; // marker | 2194 helper.$name; // marker |
| 2195 }'''; | 2195 }'''; |
| 2196 | 2196 |
| 2197 SimpleIdentifier id = await findMarkedIdentifier(code, "; // marker"); | 2197 CompilationUnit unit = await resolveSource(code); |
| 2198 SimpleIdentifier id = findMarkedIdentifier(code, unit, "; // marker"); |
| 2198 PrefixedIdentifier prefixedId = id.parent; | 2199 PrefixedIdentifier prefixedId = id.parent; |
| 2199 expect(id.staticType, typeProvider.dynamicType); | 2200 expect(id.staticType, typeProvider.dynamicType); |
| 2200 expect(prefixedId.staticType, typeProvider.dynamicType); | 2201 expect(prefixedId.staticType, typeProvider.dynamicType); |
| 2201 } | 2202 } |
| 2202 | 2203 |
| 2203 test_objectAccessInference_disabled_for_local_getter() async { | 2204 test_objectAccessInference_disabled_for_local_getter() async { |
| 2204 String name = 'hashCode'; | 2205 String name = 'hashCode'; |
| 2205 String code = ''' | 2206 String code = ''' |
| 2206 dynamic get $name => null; | 2207 dynamic get $name => null; |
| 2207 main() { | 2208 main() { |
| 2208 $name; // marker | 2209 $name; // marker |
| 2209 }'''; | 2210 }'''; |
| 2210 | 2211 |
| 2211 SimpleIdentifier getter = await findMarkedIdentifier(code, "; // marker"); | 2212 CompilationUnit unit = await resolveSource(code); |
| 2213 SimpleIdentifier getter = findMarkedIdentifier(code, unit, "; // marker"); |
| 2212 expect(getter.staticType, typeProvider.dynamicType); | 2214 expect(getter.staticType, typeProvider.dynamicType); |
| 2213 } | 2215 } |
| 2214 | 2216 |
| 2215 test_objectAccessInference_enabled_for_cascades() async { | 2217 test_objectAccessInference_enabled_for_cascades() async { |
| 2216 String name = 'hashCode'; | 2218 String name = 'hashCode'; |
| 2217 String code = ''' | 2219 String code = ''' |
| 2218 main() { | 2220 main() { |
| 2219 dynamic obj; | 2221 dynamic obj; |
| 2220 obj..$name..$name; // marker | 2222 obj..$name..$name; // marker |
| 2221 }'''; | 2223 }'''; |
| 2224 CompilationUnit unit = await resolveSource(code); |
| 2222 PropertyAccess access = | 2225 PropertyAccess access = |
| 2223 (await findMarkedIdentifier(code, "; // marker")).parent; | 2226 findMarkedIdentifier(code, unit, "; // marker").parent; |
| 2224 expect(access.staticType, typeProvider.dynamicType); | 2227 expect(access.staticType, typeProvider.dynamicType); |
| 2225 expect(access.realTarget.staticType, typeProvider.dynamicType); | 2228 expect(access.realTarget.staticType, typeProvider.dynamicType); |
| 2226 } | 2229 } |
| 2227 | 2230 |
| 2228 test_objectMethodInference_disabled_for_library_prefix() async { | 2231 test_objectMethodInference_disabled_for_library_prefix() async { |
| 2229 String name = 'toString'; | 2232 String name = 'toString'; |
| 2230 addNamedSource( | 2233 addNamedSource( |
| 2231 '/helper.dart', | 2234 '/helper.dart', |
| 2232 ''' | 2235 ''' |
| 2233 library helper; | 2236 library helper; |
| 2234 dynamic $name = (int x) => x + 42'); | 2237 dynamic $name = (int x) => x + 42'); |
| 2235 '''); | 2238 '''); |
| 2236 String code = ''' | 2239 String code = ''' |
| 2237 import 'helper.dart' as helper; | 2240 import 'helper.dart' as helper; |
| 2238 main() { | 2241 main() { |
| 2239 helper.$name(); // marker | 2242 helper.$name(); // marker |
| 2240 }'''; | 2243 }'''; |
| 2244 CompilationUnit unit = await resolveSource(code); |
| 2241 SimpleIdentifier methodName = | 2245 SimpleIdentifier methodName = |
| 2242 await findMarkedIdentifier(code, "(); // marker"); | 2246 findMarkedIdentifier(code, unit, "(); // marker"); |
| 2243 MethodInvocation methodInvoke = methodName.parent; | 2247 MethodInvocation methodInvoke = methodName.parent; |
| 2244 expect(methodName.staticType, typeProvider.dynamicType); | 2248 expect(methodName.staticType, typeProvider.dynamicType); |
| 2245 expect(methodInvoke.staticType, typeProvider.dynamicType); | 2249 expect(methodInvoke.staticType, typeProvider.dynamicType); |
| 2246 } | 2250 } |
| 2247 | 2251 |
| 2248 test_objectMethodInference_disabled_for_local_function() async { | 2252 test_objectMethodInference_disabled_for_local_function() async { |
| 2249 String name = 'toString'; | 2253 String name = 'toString'; |
| 2250 String code = ''' | 2254 String code = ''' |
| 2251 main() { | 2255 main() { |
| 2252 dynamic $name = () => null; | 2256 dynamic $name = () => null; |
| 2253 $name(); // marker | 2257 $name(); // marker |
| 2254 }'''; | 2258 }'''; |
| 2255 SimpleIdentifier identifier = await findMarkedIdentifier(code, "$name = "); | 2259 CompilationUnit unit = await resolveSource(code); |
| 2260 |
| 2261 SimpleIdentifier identifier = findMarkedIdentifier(code, unit, "$name = "); |
| 2256 expect(identifier.staticType, typeProvider.dynamicType); | 2262 expect(identifier.staticType, typeProvider.dynamicType); |
| 2257 | 2263 |
| 2258 SimpleIdentifier methodName = | 2264 SimpleIdentifier methodName = |
| 2259 await findMarkedIdentifier(code, "(); // marker"); | 2265 findMarkedIdentifier(code, unit, "(); // marker"); |
| 2260 MethodInvocation methodInvoke = methodName.parent; | 2266 MethodInvocation methodInvoke = methodName.parent; |
| 2261 expect(methodName.staticType, typeProvider.dynamicType); | 2267 expect(methodName.staticType, typeProvider.dynamicType); |
| 2262 expect(methodInvoke.staticType, typeProvider.dynamicType); | 2268 expect(methodInvoke.staticType, typeProvider.dynamicType); |
| 2263 } | 2269 } |
| 2264 | 2270 |
| 2265 test_objectMethodInference_enabled_for_cascades() async { | 2271 test_objectMethodInference_enabled_for_cascades() async { |
| 2266 String name = 'toString'; | 2272 String name = 'toString'; |
| 2267 String code = ''' | 2273 String code = ''' |
| 2268 main() { | 2274 main() { |
| 2269 dynamic obj; | 2275 dynamic obj; |
| 2270 obj..$name()..$name(); // marker | 2276 obj..$name()..$name(); // marker |
| 2271 }'''; | 2277 }'''; |
| 2278 CompilationUnit unit = await resolveSource(code); |
| 2272 SimpleIdentifier methodName = | 2279 SimpleIdentifier methodName = |
| 2273 await findMarkedIdentifier(code, "(); // marker"); | 2280 findMarkedIdentifier(code, unit, "(); // marker"); |
| 2274 MethodInvocation methodInvoke = methodName.parent; | 2281 MethodInvocation methodInvoke = methodName.parent; |
| 2275 | 2282 |
| 2276 expect(methodInvoke.staticType, typeProvider.dynamicType); | 2283 expect(methodInvoke.staticType, typeProvider.dynamicType); |
| 2277 expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType); | 2284 expect(methodInvoke.realTarget.staticType, typeProvider.dynamicType); |
| 2278 } | 2285 } |
| 2279 | 2286 |
| 2280 test_objectMethodOnDynamicExpression_doubleEquals() async { | 2287 test_objectMethodOnDynamicExpression_doubleEquals() async { |
| 2281 // https://code.google.com/p/dart/issues/detail?id=20342 | 2288 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 2282 // | 2289 // |
| 2283 // This was not actually part of Issue 20342, since the spec specifies a | 2290 // This was not actually part of Issue 20342, since the spec specifies a |
| 2284 // static type of [bool] for [==] comparison and the implementation | 2291 // static type of [bool] for [==] comparison and the implementation |
| 2285 // was already consistent with the spec there. But, it's another | 2292 // was already consistent with the spec there. But, it's another |
| 2286 // [Object] method, so it's included here. | 2293 // [Object] method, so it's included here. |
| 2287 await assertTypeOfMarkedExpression( | 2294 var code = r''' |
| 2288 r''' | |
| 2289 f1(x) { | 2295 f1(x) { |
| 2290 var v = (x == x); | 2296 var v = (x == x); |
| 2291 return v; // marker | 2297 return v; // marker |
| 2292 }''', | 2298 }'''; |
| 2293 null, | 2299 CompilationUnit unit = await resolveSource(code); |
| 2294 typeProvider.boolType); | 2300 assertTypeOfMarkedExpression(code, unit, null, typeProvider.boolType); |
| 2295 } | 2301 } |
| 2296 | 2302 |
| 2297 test_objectMethodOnDynamicExpression_hashCode() async { | 2303 test_objectMethodOnDynamicExpression_hashCode() async { |
| 2298 // https://code.google.com/p/dart/issues/detail?id=20342 | 2304 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 2299 await assertTypeOfMarkedExpression( | 2305 var code = r''' |
| 2300 r''' | |
| 2301 f1(x) { | 2306 f1(x) { |
| 2302 var v = x.hashCode; | 2307 var v = x.hashCode; |
| 2303 return v; // marker | 2308 return v; // marker |
| 2304 }''', | 2309 }'''; |
| 2305 null, | 2310 CompilationUnit unit = await resolveSource(code); |
| 2306 typeProvider.intType); | 2311 assertTypeOfMarkedExpression(code, unit, null, typeProvider.intType); |
| 2307 } | 2312 } |
| 2308 | 2313 |
| 2309 test_objectMethodOnDynamicExpression_runtimeType() async { | 2314 test_objectMethodOnDynamicExpression_runtimeType() async { |
| 2310 // https://code.google.com/p/dart/issues/detail?id=20342 | 2315 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 2311 await assertTypeOfMarkedExpression( | 2316 var code = r''' |
| 2312 r''' | |
| 2313 f1(x) { | 2317 f1(x) { |
| 2314 var v = x.runtimeType; | 2318 var v = x.runtimeType; |
| 2315 return v; // marker | 2319 return v; // marker |
| 2316 }''', | 2320 }'''; |
| 2317 null, | 2321 CompilationUnit unit = await resolveSource(code); |
| 2318 typeProvider.typeType); | 2322 assertTypeOfMarkedExpression(code, unit, null, typeProvider.typeType); |
| 2319 } | 2323 } |
| 2320 | 2324 |
| 2321 test_objectMethodOnDynamicExpression_toString() async { | 2325 test_objectMethodOnDynamicExpression_toString() async { |
| 2322 // https://code.google.com/p/dart/issues/detail?id=20342 | 2326 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 2323 await assertTypeOfMarkedExpression( | 2327 var code = r''' |
| 2324 r''' | |
| 2325 f1(x) { | 2328 f1(x) { |
| 2326 var v = x.toString(); | 2329 var v = x.toString(); |
| 2327 return v; // marker | 2330 return v; // marker |
| 2328 }''', | 2331 }'''; |
| 2329 null, | 2332 CompilationUnit unit = await resolveSource(code); |
| 2330 typeProvider.stringType); | 2333 assertTypeOfMarkedExpression(code, unit, null, typeProvider.stringType); |
| 2331 } | 2334 } |
| 2332 | 2335 |
| 2333 test_propagatedReturnType_localFunction() async { | 2336 test_propagatedReturnType_localFunction() async { |
| 2334 String code = r''' | 2337 String code = r''' |
| 2335 main() { | 2338 main() { |
| 2336 f() => 42; | 2339 f() => 42; |
| 2337 var v = f(); | 2340 var v = f(); |
| 2338 }'''; | 2341 }'''; |
| 2339 await assertPropagatedAssignedType( | 2342 CompilationUnit unit = await resolveSource(code); |
| 2340 code, typeProvider.dynamicType, typeProvider.intType); | 2343 assertPropagatedAssignedType( |
| 2344 code, unit, typeProvider.dynamicType, typeProvider.intType); |
| 2341 } | 2345 } |
| 2342 | 2346 |
| 2343 test_query() async { | 2347 test_query() async { |
| 2344 Source source = addSource(r''' | 2348 Source source = addSource(r''' |
| 2345 import 'dart:html'; | 2349 import 'dart:html'; |
| 2346 | 2350 |
| 2347 main() { | 2351 main() { |
| 2348 var v1 = query('a'); | 2352 var v1 = query('a'); |
| 2349 var v2 = query('A'); | 2353 var v2 = query('A'); |
| 2350 var v3 = query('body:active'); | 2354 var v3 = query('body:active'); |
| (...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3610 */ | 3614 */ |
| 3611 class _StaleElement extends ElementImpl { | 3615 class _StaleElement extends ElementImpl { |
| 3612 _StaleElement() : super("_StaleElement", -1); | 3616 _StaleElement() : super("_StaleElement", -1); |
| 3613 | 3617 |
| 3614 @override | 3618 @override |
| 3615 get kind => throw "_StaleElement's kind shouldn't be accessed"; | 3619 get kind => throw "_StaleElement's kind shouldn't be accessed"; |
| 3616 | 3620 |
| 3617 @override | 3621 @override |
| 3618 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; | 3622 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; |
| 3619 } | 3623 } |
| OLD | NEW |