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/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 7956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7967 * @param contents the contents to be returned by the content provider for the
specified file | 7967 * @param contents the contents to be returned by the content provider for the
specified file |
7968 * @return the source object representing the cached file | 7968 * @return the source object representing the cached file |
7969 */ | 7969 */ |
7970 Source cacheSource(String filePath, String contents) { | 7970 Source cacheSource(String filePath, String contents) { |
7971 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); | 7971 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); |
7972 analysisContext2.setContents(source, contents); | 7972 analysisContext2.setContents(source, contents); |
7973 return source; | 7973 return source; |
7974 } | 7974 } |
7975 | 7975 |
7976 /** | 7976 /** |
| 7977 * Change the contents of the given [source] to the given [contents]. |
| 7978 */ |
| 7979 void changeSource(Source source, String contents) { |
| 7980 analysisContext2.setContents(source, contents); |
| 7981 ChangeSet changeSet = new ChangeSet(); |
| 7982 changeSet.changedSource(source); |
| 7983 analysisContext2.applyChanges(changeSet); |
| 7984 } |
| 7985 |
| 7986 /** |
7977 * Computes errors for the given [librarySource]. | 7987 * Computes errors for the given [librarySource]. |
7978 * This assumes that the given [librarySource] and its parts have already | 7988 * This assumes that the given [librarySource] and its parts have already |
7979 * been added to the content provider using the method [addNamedSource]. | 7989 * been added to the content provider using the method [addNamedSource]. |
7980 */ | 7990 */ |
7981 void computeLibrarySourceErrors(Source librarySource) { | 7991 void computeLibrarySourceErrors(Source librarySource) { |
7982 analysisContext.computeErrors(librarySource); | 7992 analysisContext.computeErrors(librarySource); |
7983 } | 7993 } |
7984 | 7994 |
7985 /** | 7995 /** |
7986 * Create a library element that represents a library named `"test"` containin
g a single | 7996 * Create a library element that represents a library named `"test"` containin
g a single |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8047 return variable; | 8057 return variable; |
8048 } | 8058 } |
8049 } | 8059 } |
8050 } | 8060 } |
8051 } | 8061 } |
8052 return null; | 8062 return null; |
8053 // Not found | 8063 // Not found |
8054 } | 8064 } |
8055 | 8065 |
8056 /** | 8066 /** |
8057 * @param code the code that iterates using variable "v". We check that | |
8058 * "v" has expected static and propagated type. | |
8059 */ | |
8060 void _assertPropagatedIterationType(String code, DartType expectedStaticType, | |
8061 DartType expectedPropagatedType) { | |
8062 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v in "); | |
8063 expect(identifier.staticType, same(expectedStaticType)); | |
8064 expect(identifier.propagatedType, same(expectedPropagatedType)); | |
8065 } | |
8066 | |
8067 /** | |
8068 * @param code the code that assigns the value to the variable "v", no matter
how. We check that | |
8069 * "v" has expected static and propagated type. | |
8070 */ | |
8071 void _assertPropagatedAssignedType(String code, DartType expectedStaticType, | |
8072 DartType expectedPropagatedType) { | |
8073 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); | |
8074 expect(identifier.staticType, same(expectedStaticType)); | |
8075 expect(identifier.propagatedType, same(expectedPropagatedType)); | |
8076 } | |
8077 | |
8078 /** | |
8079 * Check the static and propagated types of the expression marked with "; // m
arker" comment. | |
8080 * | |
8081 * @param code source code to analyze, with the expression to check marked wit
h "// marker". | |
8082 * @param expectedStaticType if non-null, check actual static type is equal to
this. | |
8083 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. | |
8084 * @throws Exception | |
8085 */ | |
8086 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, | |
8087 DartType expectedPropagatedType) { | |
8088 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); | |
8089 if (expectedStaticType != null) { | |
8090 expect(identifier.staticType, expectedStaticType); | |
8091 } | |
8092 expect(identifier.propagatedType, expectedPropagatedType); | |
8093 } | |
8094 | |
8095 /** | |
8096 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no | |
8097 * errors and be verifiable. | |
8098 * | |
8099 * @param code source code to analyze. | |
8100 * @param marker marker identifying sought after expression in source code. | |
8101 * @return expression marked by the marker. | |
8102 * @throws Exception | |
8103 */ | |
8104 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { | |
8105 try { | |
8106 Source source = addSource(code); | |
8107 LibraryElement library = resolve2(source); | |
8108 assertNoErrors(source); | |
8109 verify([source]); | |
8110 CompilationUnit unit = resolveCompilationUnit(source, library); | |
8111 // Could generalize this further by making [SimpleIdentifier.class] a | |
8112 // parameter. | |
8113 return EngineTestCase.findNode( | |
8114 unit, code, marker, (node) => node is SimpleIdentifier); | |
8115 } catch (exception) { | |
8116 // Is there a better exception to throw here? The point is that an | |
8117 // assertion failure here should be a failure, in both "test_*" and | |
8118 // "fail_*" tests. However, an assertion failure is success for the | |
8119 // purpose of "fail_*" tests, so without catching them here "fail_*" tests | |
8120 // can succeed by failing for the wrong reason. | |
8121 throw new JavaException("Unexexpected assertion failure: $exception"); | |
8122 } | |
8123 } | |
8124 | |
8125 /** | |
8126 * In the rare cases we want to group several tests into single "test_" method
, so need a way to | 8067 * In the rare cases we want to group several tests into single "test_" method
, so need a way to |
8127 * reset test instance to reuse it. | 8068 * reset test instance to reuse it. |
8128 */ | 8069 */ |
8129 void reset() { | 8070 void reset() { |
8130 analysisContext2 = AnalysisContextFactory.contextWithCore(); | 8071 analysisContext2 = AnalysisContextFactory.contextWithCore(); |
8131 } | 8072 } |
8132 | 8073 |
8133 /** | 8074 /** |
8134 * Reset the analysis context to have the given options applied. | 8075 * Reset the analysis context to have the given options applied. |
8135 * | 8076 * |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8234 for (Source library in libraries) { | 8175 for (Source library in libraries) { |
8235 analysisContext2 | 8176 analysisContext2 |
8236 .resolveCompilationUnit2(source, library) | 8177 .resolveCompilationUnit2(source, library) |
8237 .accept(verifier); | 8178 .accept(verifier); |
8238 } | 8179 } |
8239 } | 8180 } |
8240 verifier.assertResolved(); | 8181 verifier.assertResolved(); |
8241 } | 8182 } |
8242 | 8183 |
8243 /** | 8184 /** |
| 8185 * @param code the code that assigns the value to the variable "v", no matter
how. We check that |
| 8186 * "v" has expected static and propagated type. |
| 8187 */ |
| 8188 void _assertPropagatedAssignedType(String code, DartType expectedStaticType, |
| 8189 DartType expectedPropagatedType) { |
| 8190 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); |
| 8191 expect(identifier.staticType, same(expectedStaticType)); |
| 8192 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 8193 } |
| 8194 |
| 8195 /** |
| 8196 * @param code the code that iterates using variable "v". We check that |
| 8197 * "v" has expected static and propagated type. |
| 8198 */ |
| 8199 void _assertPropagatedIterationType(String code, DartType expectedStaticType, |
| 8200 DartType expectedPropagatedType) { |
| 8201 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v in "); |
| 8202 expect(identifier.staticType, same(expectedStaticType)); |
| 8203 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 8204 } |
| 8205 |
| 8206 /** |
| 8207 * Check the static and propagated types of the expression marked with "; // m
arker" comment. |
| 8208 * |
| 8209 * @param code source code to analyze, with the expression to check marked wit
h "// marker". |
| 8210 * @param expectedStaticType if non-null, check actual static type is equal to
this. |
| 8211 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. |
| 8212 * @throws Exception |
| 8213 */ |
| 8214 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, |
| 8215 DartType expectedPropagatedType) { |
| 8216 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); |
| 8217 if (expectedStaticType != null) { |
| 8218 expect(identifier.staticType, expectedStaticType); |
| 8219 } |
| 8220 expect(identifier.propagatedType, expectedPropagatedType); |
| 8221 } |
| 8222 |
| 8223 /** |
8244 * Create a source object representing a file with the given [fileName] and | 8224 * Create a source object representing a file with the given [fileName] and |
8245 * give it an empty content. Return the source that was created. | 8225 * give it an empty content. Return the source that was created. |
8246 */ | 8226 */ |
8247 FileBasedSource _createNamedSource(String fileName) { | 8227 FileBasedSource _createNamedSource(String fileName) { |
8248 FileBasedSource source = | 8228 FileBasedSource source = |
8249 new FileBasedSource(FileUtilities2.createFile(fileName)); | 8229 new FileBasedSource(FileUtilities2.createFile(fileName)); |
8250 analysisContext2.setContents(source, ""); | 8230 analysisContext2.setContents(source, ""); |
8251 return source; | 8231 return source; |
8252 } | 8232 } |
| 8233 |
| 8234 /** |
| 8235 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no |
| 8236 * errors and be verifiable. |
| 8237 * |
| 8238 * @param code source code to analyze. |
| 8239 * @param marker marker identifying sought after expression in source code. |
| 8240 * @return expression marked by the marker. |
| 8241 * @throws Exception |
| 8242 */ |
| 8243 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { |
| 8244 try { |
| 8245 Source source = addSource(code); |
| 8246 LibraryElement library = resolve2(source); |
| 8247 assertNoErrors(source); |
| 8248 verify([source]); |
| 8249 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 8250 // Could generalize this further by making [SimpleIdentifier.class] a |
| 8251 // parameter. |
| 8252 return EngineTestCase.findNode( |
| 8253 unit, code, marker, (node) => node is SimpleIdentifier); |
| 8254 } catch (exception) { |
| 8255 // Is there a better exception to throw here? The point is that an |
| 8256 // assertion failure here should be a failure, in both "test_*" and |
| 8257 // "fail_*" tests. However, an assertion failure is success for the |
| 8258 // purpose of "fail_*" tests, so without catching them here "fail_*" tests |
| 8259 // can succeed by failing for the wrong reason. |
| 8260 throw new JavaException("Unexexpected assertion failure: $exception"); |
| 8261 } |
| 8262 } |
8253 } | 8263 } |
8254 | 8264 |
8255 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { | 8265 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { |
8256 GatheringErrorListener listener; | 8266 GatheringErrorListener listener; |
8257 | 8267 |
8258 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super(); | 8268 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super(); |
8259 | 8269 |
8260 @override | 8270 @override |
8261 AnalysisErrorListener get errorListener => listener; | 8271 AnalysisErrorListener get errorListener => listener; |
8262 | 8272 |
(...skipping 3600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11863 int f() { | 11873 int f() { |
11864 num n = 1234; | 11874 num n = 1234; |
11865 return n & 0x0F; | 11875 return n & 0x0F; |
11866 }'''); | 11876 }'''); |
11867 computeLibrarySourceErrors(source); | 11877 computeLibrarySourceErrors(source); |
11868 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11878 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
11869 } | 11879 } |
11870 } | 11880 } |
11871 | 11881 |
11872 @reflectiveTest | 11882 @reflectiveTest |
| 11883 class StrongModeTypePropagationTest extends ResolverTestCase { |
| 11884 void fail_localVariableInference_transitive_field_inferred_lexical() { |
| 11885 String code = r''' |
| 11886 class A { |
| 11887 final x = 3; |
| 11888 f() { |
| 11889 var v = x; |
| 11890 return v; // marker |
| 11891 } |
| 11892 } |
| 11893 main() { |
| 11894 } |
| 11895 '''; |
| 11896 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 11897 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11898 } |
| 11899 |
| 11900 void fail_localVariableInference_transitive_field_inferred_reversed() { |
| 11901 String code = r''' |
| 11902 class A { |
| 11903 f() { |
| 11904 var v = x; |
| 11905 return v; // marker |
| 11906 } |
| 11907 final x = 3; |
| 11908 } |
| 11909 main() { |
| 11910 } |
| 11911 '''; |
| 11912 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 11913 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11914 } |
| 11915 |
| 11916 void fail_localVariableInference_transitive_toplevel_inferred_lexical() { |
| 11917 String code = r''' |
| 11918 final x = 3; |
| 11919 main() { |
| 11920 var v = x; |
| 11921 return v; // marker |
| 11922 } |
| 11923 '''; |
| 11924 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 11925 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11926 } |
| 11927 |
| 11928 void fail_localVariableInference_transitive_toplevel_inferred_reversed() { |
| 11929 String code = r''' |
| 11930 main() { |
| 11931 var v = x; |
| 11932 return v; // marker |
| 11933 } |
| 11934 final x = 3; |
| 11935 '''; |
| 11936 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 11937 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11938 } |
| 11939 |
| 11940 @override |
| 11941 void setUp() { |
| 11942 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 11943 options.strongMode = true; |
| 11944 resetWithOptions(options); |
| 11945 } |
| 11946 |
| 11947 void test_foreachInference_dynamic_disabled() { |
| 11948 String code = r''' |
| 11949 main() { |
| 11950 var list = <int>[]; |
| 11951 for (dynamic v in list) { |
| 11952 v; // marker |
| 11953 } |
| 11954 }'''; |
| 11955 _assertPropagatedIterationType( |
| 11956 code, typeProvider.dynamicType, typeProvider.intType); |
| 11957 _assertTypeOfMarkedExpression( |
| 11958 code, typeProvider.dynamicType, typeProvider.intType); |
| 11959 } |
| 11960 |
| 11961 void test_foreachInference_reusedVar_disabled() { |
| 11962 String code = r''' |
| 11963 main() { |
| 11964 var list = <int>[]; |
| 11965 var v; |
| 11966 for (v in list) { |
| 11967 v; // marker |
| 11968 } |
| 11969 }'''; |
| 11970 _assertPropagatedIterationType( |
| 11971 code, typeProvider.dynamicType, typeProvider.intType); |
| 11972 _assertTypeOfMarkedExpression( |
| 11973 code, typeProvider.dynamicType, typeProvider.intType); |
| 11974 } |
| 11975 |
| 11976 void test_foreachInference_var() { |
| 11977 String code = r''' |
| 11978 main() { |
| 11979 var list = <int>[]; |
| 11980 for (var v in list) { |
| 11981 v; // marker |
| 11982 } |
| 11983 }'''; |
| 11984 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 11985 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11986 } |
| 11987 |
| 11988 void test_foreachInference_var_iterable() { |
| 11989 String code = r''' |
| 11990 main() { |
| 11991 Iterable<int> list = <int>[]; |
| 11992 for (var v in list) { |
| 11993 v; // marker |
| 11994 } |
| 11995 }'''; |
| 11996 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 11997 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 11998 } |
| 11999 |
| 12000 void test_foreachInference_var_stream() { |
| 12001 String code = r''' |
| 12002 import 'dart:async'; |
| 12003 main() async { |
| 12004 Stream<int> stream = null; |
| 12005 await for (var v in stream) { |
| 12006 v; // marker |
| 12007 } |
| 12008 }'''; |
| 12009 _assertPropagatedIterationType(code, typeProvider.intType, null); |
| 12010 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12011 } |
| 12012 |
| 12013 void test_localVariableInference_bottom_disabled() { |
| 12014 String code = r''' |
| 12015 main() { |
| 12016 var v = null; |
| 12017 return v; // marker |
| 12018 }'''; |
| 12019 _assertPropagatedAssignedType(code, typeProvider.dynamicType, null); |
| 12020 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); |
| 12021 } |
| 12022 |
| 12023 void test_localVariableInference_constant() { |
| 12024 String code = r''' |
| 12025 main() { |
| 12026 var v = 3; |
| 12027 return v; // marker |
| 12028 }'''; |
| 12029 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12030 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12031 } |
| 12032 |
| 12033 void test_localVariableInference_declaredType_disabled() { |
| 12034 String code = r''' |
| 12035 main() { |
| 12036 dynamic v = 3; |
| 12037 return v; // marker |
| 12038 }'''; |
| 12039 _assertPropagatedAssignedType( |
| 12040 code, typeProvider.dynamicType, typeProvider.intType); |
| 12041 _assertTypeOfMarkedExpression( |
| 12042 code, typeProvider.dynamicType, typeProvider.intType); |
| 12043 } |
| 12044 |
| 12045 void test_localVariableInference_noInitializer_disabled() { |
| 12046 String code = r''' |
| 12047 main() { |
| 12048 var v; |
| 12049 v = 3; |
| 12050 return v; // marker |
| 12051 }'''; |
| 12052 _assertPropagatedAssignedType( |
| 12053 code, typeProvider.dynamicType, typeProvider.intType); |
| 12054 _assertTypeOfMarkedExpression( |
| 12055 code, typeProvider.dynamicType, typeProvider.intType); |
| 12056 } |
| 12057 |
| 12058 void test_localVariableInference_transitive_field_lexical() { |
| 12059 String code = r''' |
| 12060 class A { |
| 12061 int x = 3; |
| 12062 f() { |
| 12063 var v = x; |
| 12064 return v; // marker |
| 12065 } |
| 12066 } |
| 12067 main() { |
| 12068 } |
| 12069 '''; |
| 12070 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12071 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12072 } |
| 12073 |
| 12074 void test_localVariableInference_transitive_field_reversed() { |
| 12075 String code = r''' |
| 12076 class A { |
| 12077 f() { |
| 12078 var v = x; |
| 12079 return v; // marker |
| 12080 } |
| 12081 int x = 3; |
| 12082 } |
| 12083 main() { |
| 12084 } |
| 12085 '''; |
| 12086 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12087 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12088 } |
| 12089 |
| 12090 void test_localVariableInference_transitive_list_local() { |
| 12091 String code = r''' |
| 12092 main() { |
| 12093 var x = <int>[3]; |
| 12094 var v = x[0]; |
| 12095 return v; // marker |
| 12096 }'''; |
| 12097 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12098 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12099 } |
| 12100 |
| 12101 void test_localVariableInference_transitive_local() { |
| 12102 String code = r''' |
| 12103 main() { |
| 12104 var x = 3; |
| 12105 var v = x; |
| 12106 return v; // marker |
| 12107 }'''; |
| 12108 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12109 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12110 } |
| 12111 |
| 12112 void test_localVariableInference_transitive_toplevel_lexical() { |
| 12113 String code = r''' |
| 12114 int x = 3; |
| 12115 main() { |
| 12116 var v = x; |
| 12117 return v; // marker |
| 12118 } |
| 12119 '''; |
| 12120 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12121 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12122 } |
| 12123 |
| 12124 void test_localVariableInference_transitive_toplevel_reversed() { |
| 12125 String code = r''' |
| 12126 main() { |
| 12127 var v = x; |
| 12128 return v; // marker |
| 12129 } |
| 12130 int x = 3; |
| 12131 '''; |
| 12132 _assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 12133 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 12134 } |
| 12135 } |
| 12136 |
| 12137 @reflectiveTest |
11873 class SubtypeManagerTest extends EngineTestCase { | 12138 class SubtypeManagerTest extends EngineTestCase { |
11874 /** | 12139 /** |
11875 * The inheritance manager being tested. | 12140 * The inheritance manager being tested. |
11876 */ | 12141 */ |
11877 SubtypeManager _subtypeManager; | 12142 SubtypeManager _subtypeManager; |
11878 | 12143 |
11879 /** | 12144 /** |
11880 * The compilation unit element containing all of the types setup in each test
. | 12145 * The compilation unit element containing all of the types setup in each test
. |
11881 */ | 12146 */ |
11882 CompilationUnitElementImpl _definingCompilationUnit; | 12147 CompilationUnitElementImpl _definingCompilationUnit; |
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13490 expect(elements[5].propagatedType.name, "InputElement"); | 13755 expect(elements[5].propagatedType.name, "InputElement"); |
13491 expect(elements[6].propagatedType.name, "SelectElement"); | 13756 expect(elements[6].propagatedType.name, "SelectElement"); |
13492 expect(elements[7].propagatedType.name, "DivElement"); | 13757 expect(elements[7].propagatedType.name, "DivElement"); |
13493 expect(elements[8].propagatedType.name, "Element"); | 13758 expect(elements[8].propagatedType.name, "Element"); |
13494 expect(elements[9].propagatedType.name, "Element"); | 13759 expect(elements[9].propagatedType.name, "Element"); |
13495 expect(elements[10].propagatedType.name, "Element"); | 13760 expect(elements[10].propagatedType.name, "Element"); |
13496 } | 13761 } |
13497 } | 13762 } |
13498 | 13763 |
13499 @reflectiveTest | 13764 @reflectiveTest |
13500 class StrongModeTypePropagationTest extends ResolverTestCase { | |
13501 @override | |
13502 void setUp() { | |
13503 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
13504 options.strongMode = true; | |
13505 resetWithOptions(options); | |
13506 } | |
13507 | |
13508 void test_localVariableInference_constant() { | |
13509 String code = r''' | |
13510 main() { | |
13511 var v = 3; | |
13512 return v; // marker | |
13513 }'''; | |
13514 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13515 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13516 } | |
13517 | |
13518 void test_localVariableInference_transitive_local() { | |
13519 String code = r''' | |
13520 main() { | |
13521 var x = 3; | |
13522 var v = x; | |
13523 return v; // marker | |
13524 }'''; | |
13525 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13526 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13527 } | |
13528 | |
13529 void test_localVariableInference_transitive_list_local() { | |
13530 String code = r''' | |
13531 main() { | |
13532 var x = <int>[3]; | |
13533 var v = x[0]; | |
13534 return v; // marker | |
13535 }'''; | |
13536 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13537 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13538 } | |
13539 | |
13540 void test_localVariableInference_transitive_toplevel_lexical() { | |
13541 String code = r''' | |
13542 int x = 3; | |
13543 main() { | |
13544 var v = x; | |
13545 return v; // marker | |
13546 } | |
13547 '''; | |
13548 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13549 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13550 } | |
13551 | |
13552 void test_localVariableInference_transitive_toplevel_reversed() { | |
13553 String code = r''' | |
13554 main() { | |
13555 var v = x; | |
13556 return v; // marker | |
13557 } | |
13558 int x = 3; | |
13559 '''; | |
13560 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13561 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13562 } | |
13563 | |
13564 void fail_localVariableInference_transitive_toplevel_inferred_lexical() { | |
13565 String code = r''' | |
13566 final x = 3; | |
13567 main() { | |
13568 var v = x; | |
13569 return v; // marker | |
13570 } | |
13571 '''; | |
13572 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13573 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13574 } | |
13575 | |
13576 void fail_localVariableInference_transitive_toplevel_inferred_reversed() { | |
13577 String code = r''' | |
13578 main() { | |
13579 var v = x; | |
13580 return v; // marker | |
13581 } | |
13582 final x = 3; | |
13583 '''; | |
13584 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13585 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13586 } | |
13587 | |
13588 void test_localVariableInference_transitive_field_lexical() { | |
13589 String code = r''' | |
13590 class A { | |
13591 int x = 3; | |
13592 f() { | |
13593 var v = x; | |
13594 return v; // marker | |
13595 } | |
13596 } | |
13597 main() { | |
13598 } | |
13599 '''; | |
13600 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13601 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13602 } | |
13603 | |
13604 void test_localVariableInference_transitive_field_reversed() { | |
13605 String code = r''' | |
13606 class A { | |
13607 f() { | |
13608 var v = x; | |
13609 return v; // marker | |
13610 } | |
13611 int x = 3; | |
13612 } | |
13613 main() { | |
13614 } | |
13615 '''; | |
13616 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13617 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13618 } | |
13619 | |
13620 void fail_localVariableInference_transitive_field_inferred_lexical() { | |
13621 String code = r''' | |
13622 class A { | |
13623 final x = 3; | |
13624 f() { | |
13625 var v = x; | |
13626 return v; // marker | |
13627 } | |
13628 } | |
13629 main() { | |
13630 } | |
13631 '''; | |
13632 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13633 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13634 } | |
13635 | |
13636 void fail_localVariableInference_transitive_field_inferred_reversed() { | |
13637 String code = r''' | |
13638 class A { | |
13639 f() { | |
13640 var v = x; | |
13641 return v; // marker | |
13642 } | |
13643 final x = 3; | |
13644 } | |
13645 main() { | |
13646 } | |
13647 '''; | |
13648 _assertPropagatedAssignedType(code, typeProvider.intType, null); | |
13649 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13650 } | |
13651 | |
13652 void test_localVariableInference_declaredType_disabled() { | |
13653 String code = r''' | |
13654 main() { | |
13655 dynamic v = 3; | |
13656 return v; // marker | |
13657 }'''; | |
13658 _assertPropagatedAssignedType( | |
13659 code, typeProvider.dynamicType, typeProvider.intType); | |
13660 _assertTypeOfMarkedExpression( | |
13661 code, typeProvider.dynamicType, typeProvider.intType); | |
13662 } | |
13663 | |
13664 void test_localVariableInference_bottom_disabled() { | |
13665 String code = r''' | |
13666 main() { | |
13667 var v = null; | |
13668 return v; // marker | |
13669 }'''; | |
13670 _assertPropagatedAssignedType(code, typeProvider.dynamicType, null); | |
13671 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); | |
13672 } | |
13673 | |
13674 void test_localVariableInference_noInitializer_disabled() { | |
13675 String code = r''' | |
13676 main() { | |
13677 var v; | |
13678 v = 3; | |
13679 return v; // marker | |
13680 }'''; | |
13681 _assertPropagatedAssignedType( | |
13682 code, typeProvider.dynamicType, typeProvider.intType); | |
13683 _assertTypeOfMarkedExpression( | |
13684 code, typeProvider.dynamicType, typeProvider.intType); | |
13685 } | |
13686 | |
13687 void test_foreachInference_var() { | |
13688 String code = r''' | |
13689 main() { | |
13690 var list = <int>[]; | |
13691 for (var v in list) { | |
13692 v; // marker | |
13693 } | |
13694 }'''; | |
13695 _assertPropagatedIterationType(code, typeProvider.intType, null); | |
13696 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13697 } | |
13698 | |
13699 void test_foreachInference_var_iterable() { | |
13700 String code = r''' | |
13701 main() { | |
13702 Iterable<int> list = <int>[]; | |
13703 for (var v in list) { | |
13704 v; // marker | |
13705 } | |
13706 }'''; | |
13707 _assertPropagatedIterationType(code, typeProvider.intType, null); | |
13708 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13709 } | |
13710 | |
13711 void test_foreachInference_var_stream() { | |
13712 String code = r''' | |
13713 import 'dart:async'; | |
13714 main() async { | |
13715 Stream<int> stream = null; | |
13716 await for (var v in stream) { | |
13717 v; // marker | |
13718 } | |
13719 }'''; | |
13720 _assertPropagatedIterationType(code, typeProvider.intType, null); | |
13721 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); | |
13722 } | |
13723 | |
13724 void test_foreachInference_dynamic_disabled() { | |
13725 String code = r''' | |
13726 main() { | |
13727 var list = <int>[]; | |
13728 for (dynamic v in list) { | |
13729 v; // marker | |
13730 } | |
13731 }'''; | |
13732 _assertPropagatedIterationType( | |
13733 code, typeProvider.dynamicType, typeProvider.intType); | |
13734 _assertTypeOfMarkedExpression( | |
13735 code, typeProvider.dynamicType, typeProvider.intType); | |
13736 } | |
13737 | |
13738 void test_foreachInference_reusedVar_disabled() { | |
13739 String code = r''' | |
13740 main() { | |
13741 var list = <int>[]; | |
13742 var v; | |
13743 for (v in list) { | |
13744 v; // marker | |
13745 } | |
13746 }'''; | |
13747 _assertPropagatedIterationType( | |
13748 code, typeProvider.dynamicType, typeProvider.intType); | |
13749 _assertTypeOfMarkedExpression( | |
13750 code, typeProvider.dynamicType, typeProvider.intType); | |
13751 } | |
13752 } | |
13753 | |
13754 @reflectiveTest | |
13755 class TypeProviderImplTest extends EngineTestCase { | 13765 class TypeProviderImplTest extends EngineTestCase { |
13756 void test_creation() { | 13766 void test_creation() { |
13757 // | 13767 // |
13758 // Create a mock library element with the types expected to be in dart:core. | 13768 // Create a mock library element with the types expected to be in dart:core. |
13759 // We cannot use either ElementFactory or TestTypeProvider (which uses | 13769 // We cannot use either ElementFactory or TestTypeProvider (which uses |
13760 // ElementFactory) because we side-effect the elements in ways that would | 13770 // ElementFactory) because we side-effect the elements in ways that would |
13761 // break other tests. | 13771 // break other tests. |
13762 // | 13772 // |
13763 InterfaceType objectType = _classElement("Object", null).type; | 13773 InterfaceType objectType = _classElement("Object", null).type; |
13764 InterfaceType boolType = _classElement("bool", objectType).type; | 13774 InterfaceType boolType = _classElement("bool", objectType).type; |
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14528 // check propagated type | 14538 // check propagated type |
14529 FunctionType propagatedType = node.propagatedType as FunctionType; | 14539 FunctionType propagatedType = node.propagatedType as FunctionType; |
14530 expect(propagatedType.returnType, test.typeProvider.stringType); | 14540 expect(propagatedType.returnType, test.typeProvider.stringType); |
14531 } on AnalysisException catch (e, stackTrace) { | 14541 } on AnalysisException catch (e, stackTrace) { |
14532 thrownException[0] = new CaughtException(e, stackTrace); | 14542 thrownException[0] = new CaughtException(e, stackTrace); |
14533 } | 14543 } |
14534 } | 14544 } |
14535 return null; | 14545 return null; |
14536 } | 14546 } |
14537 } | 14547 } |
OLD | NEW |