Chromium Code Reviews| 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 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 void main () { | 1103 void main () { |
| 1104 var x = 3; | 1104 var x = 3; |
| 1105 List<int> l0 = []; | 1105 List<int> l0 = []; |
| 1106 } | 1106 } |
| 1107 '''); | 1107 '''); |
| 1108 await computeAnalysisResult(source); | 1108 await computeAnalysisResult(source); |
| 1109 assertNoErrors(source); | 1109 assertNoErrors(source); |
| 1110 verify([source]); | 1110 verify([source]); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 test_inferGenericInstantiation() async { | |
|
Leaf
2017/03/18 01:45:30
Can you add a short comment at the header of these
Jennifer Messerly
2017/03/18 02:00:07
Done.
| |
| 1114 var source = addSource(r''' | |
| 1115 T f<T>(T x(T t)) => x(null); | |
| 1116 S g<S>(S s) => s; | |
| 1117 test() { | |
| 1118 var h = f(g); | |
| 1119 } | |
| 1120 '''); | |
| 1121 var analysisResult = await computeAnalysisResult(source); | |
| 1122 assertNoErrors(source); | |
| 1123 verify([source]); | |
| 1124 var unit = analysisResult.unit; | |
| 1125 var h = (AstFinder.getStatementsInTopLevelFunction(unit, "test")[0] | |
| 1126 as VariableDeclarationStatement) | |
| 1127 .variables | |
| 1128 .variables[0]; | |
| 1129 _isDynamic(h.element.type); | |
| 1130 var fCall = h.initializer as MethodInvocation; | |
| 1131 expect( | |
| 1132 fCall.staticInvokeType.toString(), '((dynamic) → dynamic) → dynamic'); | |
| 1133 var g = fCall.argumentList.arguments[0]; | |
| 1134 expect(g.staticType.toString(), '(dynamic) → dynamic'); | |
| 1135 } | |
| 1136 | |
| 1137 test_inferGenericInstantiation2() async { | |
| 1138 var source = addSource(r''' | |
| 1139 T max<T extends num>(T x, T y) => x < y ? y : x; | |
| 1140 abstract class Iterable<T> { | |
| 1141 T get first; | |
| 1142 S fold<S>(S s, S f(S s, T t)); | |
| 1143 } | |
| 1144 num test(Iterable values) => values.fold(values.first as num, max); | |
| 1145 '''); | |
| 1146 var analysisResult = await computeAnalysisResult(source); | |
| 1147 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | |
|
Leaf
2017/03/18 01:45:30
Shouldn't there be an error because the inferred b
Jennifer Messerly
2017/03/18 02:00:07
it looks like we don't actually check bounds anywh
| |
| 1148 verify([source]); | |
| 1149 var unit = analysisResult.unit; | |
| 1150 var fold = (AstFinder | |
| 1151 .getTopLevelFunction(unit, 'test') | |
| 1152 .functionExpression | |
| 1153 .body as ExpressionFunctionBody) | |
| 1154 .expression as MethodInvocation; | |
| 1155 expect( | |
| 1156 fold.staticInvokeType.toString(), '(num, (num, dynamic) → num) → num'); | |
| 1157 var max = fold.argumentList.arguments[1]; | |
| 1158 // TODO(jmesserly): arguably (num, num) → num is better here. | |
| 1159 expect(max.staticType.toString(), '(dynamic, dynamic) → dynamic'); | |
| 1160 } | |
| 1161 | |
| 1113 test_inferredFieldDeclaration_propagation() async { | 1162 test_inferredFieldDeclaration_propagation() async { |
| 1114 // Regression test for https://github.com/dart-lang/sdk/issues/25546 | 1163 // Regression test for https://github.com/dart-lang/sdk/issues/25546 |
| 1115 String code = r''' | 1164 String code = r''' |
| 1116 abstract class A { | 1165 abstract class A { |
| 1117 Map<int, List<int>> get map; | 1166 Map<int, List<int>> get map; |
| 1118 } | 1167 } |
| 1119 class B extends A { | 1168 class B extends A { |
| 1120 var map = { 42: [] }; | 1169 var map = { 42: [] }; |
| 1121 } | 1170 } |
| 1122 class C extends A { | 1171 class C extends A { |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1654 String code = r''' | 1703 String code = r''' |
| 1655 class A<S, T> { | 1704 class A<S, T> { |
| 1656 S s; | 1705 S s; |
| 1657 T t; | 1706 T t; |
| 1658 } | 1707 } |
| 1659 class B<S> extends A<S, S> { B(S s); } | 1708 class B<S> extends A<S, S> { B(S s); } |
| 1660 A<int, String> test() => new B(3); | 1709 A<int, String> test() => new B(3); |
| 1661 '''; | 1710 '''; |
| 1662 Source source = addSource(code); | 1711 Source source = addSource(code); |
| 1663 TestAnalysisResult analysisResult = await computeAnalysisResult(source); | 1712 TestAnalysisResult analysisResult = await computeAnalysisResult(source); |
| 1664 assertErrors(source,[StrongModeCode.INVALID_CAST_LITERAL]); | 1713 assertErrors(source, [StrongModeCode.INVALID_CAST_LITERAL]); |
| 1665 verify([source]); | 1714 verify([source]); |
| 1666 CompilationUnit unit = analysisResult.unit; | 1715 CompilationUnit unit = analysisResult.unit; |
| 1667 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, "test"); | 1716 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, "test"); |
| 1668 ExpressionFunctionBody body = test.functionExpression.body; | 1717 ExpressionFunctionBody body = test.functionExpression.body; |
| 1669 DartType type = body.expression.staticType; | 1718 DartType type = body.expression.staticType; |
| 1670 | 1719 |
| 1671 Element elementB = AstFinder.getClass(unit, "B").element; | 1720 Element elementB = AstFinder.getClass(unit, "B").element; |
| 1672 | 1721 |
| 1673 _isInstantiationOf(_hasElement(elementB))([_isNull])(type); | 1722 _isInstantiationOf(_hasElement(elementB))([_isNull])(type); |
| 1674 } | 1723 } |
| (...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3615 var v = x; | 3664 var v = x; |
| 3616 v; // marker | 3665 v; // marker |
| 3617 } | 3666 } |
| 3618 int x = 3; | 3667 int x = 3; |
| 3619 '''; | 3668 '''; |
| 3620 CompilationUnit unit = await resolveSource(code); | 3669 CompilationUnit unit = await resolveSource(code); |
| 3621 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); | 3670 assertPropagatedAssignedType(code, unit, typeProvider.intType, null); |
| 3622 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); | 3671 assertTypeOfMarkedExpression(code, unit, typeProvider.intType, null); |
| 3623 } | 3672 } |
| 3624 } | 3673 } |
| OLD | NEW |