| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.resolver_test; | 8 library engine.resolver_test; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| 11 import 'package:analyzer/src/generated/java_junit.dart'; | 11 import 'package:analyzer/src/generated/java_junit.dart'; |
| 12 import 'package:analyzer/src/generated/source_io.dart'; | 12 import 'package:analyzer/src/generated/source_io.dart'; |
| 13 import 'package:analyzer/src/generated/error.dart'; | 13 import 'package:analyzer/src/generated/error.dart'; |
| 14 import 'package:analyzer/src/generated/scanner.dart'; | 14 import 'package:analyzer/src/generated/scanner.dart'; |
| 15 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
| 16 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 16 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 17 import 'package:analyzer/src/generated/element.dart'; | 17 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 18 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/java_engine_io.dart'; | 20 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 21 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
| 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 23 import 'package:unittest/unittest.dart' as _ut; | 23 import 'package:unittest/unittest.dart' as _ut; |
| 24 import 'test_support.dart'; | 24 import 'test_support.dart'; |
| 25 import 'ast_test.dart' show ASTFactory; | 25 import 'ast_test.dart' show ASTFactory; |
| 26 import 'element_test.dart' show ElementFactory; | 26 import 'element_test.dart' show ElementFactory; |
| 27 | 27 |
| 28 class TypePropagationTest extends ResolverTestCase { | 28 class TypePropagationTest extends ResolverTestCase { |
| 29 void fail_propagatedReturnType_functionExpression() { | 29 void fail_propagatedReturnType_functionExpression() { |
| 30 // TODO(scheglov) disabled because we don't resolve function expression |
| 30 String code = EngineTestCase.createSource(["main() {", " var v = (() {retur
n 42;})();", "}"]); | 31 String code = EngineTestCase.createSource(["main() {", " var v = (() {retur
n 42;})();", "}"]); |
| 31 check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intT
ype); | 32 check_propagatedReturnType(code, typeProvider.dynamicType, typeProvider.intT
ype); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void test_as() { | 35 void test_as() { |
| 35 Source source = addSource(EngineTestCase.createSource([ | 36 Source source = addSource(EngineTestCase.createSource([ |
| 36 "class A {", | 37 "class A {", |
| 37 " bool get g => true;", | 38 " bool get g => true;", |
| 38 "}", | 39 "}", |
| 39 "A f(var p) {", | 40 "A f(var p) {", |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 " for (var e in p) {", | 110 " for (var e in p) {", |
| 110 " e;", | 111 " e;", |
| 111 " }", | 112 " }", |
| 112 "}"]); | 113 "}"]); |
| 113 Source source = addSource(code); | 114 Source source = addSource(code); |
| 114 LibraryElement library = resolve(source); | 115 LibraryElement library = resolve(source); |
| 115 assertNoErrors(source); | 116 assertNoErrors(source); |
| 116 verify([source]); | 117 verify([source]); |
| 117 CompilationUnit unit = resolveCompilationUnit(source, library); | 118 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 118 InterfaceType stringType = typeProvider.stringType; | 119 InterfaceType stringType = typeProvider.stringType; |
| 120 // in the declaration |
| 119 { | 121 { |
| 120 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
SimpleIdentifier); | 122 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
SimpleIdentifier); |
| 121 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 123 JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| 122 } | 124 } |
| 125 // in the loop body |
| 123 { | 126 { |
| 124 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", Si
mpleIdentifier); | 127 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", Si
mpleIdentifier); |
| 125 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 128 JUnitTestCase.assertSame(stringType, identifier.propagatedType); |
| 126 } | 129 } |
| 127 } | 130 } |
| 128 | 131 |
| 129 void test_functionExpression_asInvocationArgument() { | 132 void test_functionExpression_asInvocationArgument() { |
| 130 String code = EngineTestCase.createSource([ | 133 String code = EngineTestCase.createSource([ |
| 131 "class MyMap<K, V> {", | 134 "class MyMap<K, V> {", |
| 132 " forEach(f(K key, V value)) {}", | 135 " forEach(f(K key, V value)) {}", |
| 133 "}", | 136 "}", |
| 134 "f(MyMap<int, String> m) {", | 137 "f(MyMap<int, String> m) {", |
| 135 " m.forEach((k, v) {", | 138 " m.forEach((k, v) {", |
| 136 " k;", | 139 " k;", |
| 137 " v;", | 140 " v;", |
| 138 " });", | 141 " });", |
| 139 "}"]); | 142 "}"]); |
| 140 Source source = addSource(code); | 143 Source source = addSource(code); |
| 141 LibraryElement library = resolve(source); | 144 LibraryElement library = resolve(source); |
| 142 assertNoErrors(source); | 145 assertNoErrors(source); |
| 143 verify([source]); | 146 verify([source]); |
| 144 CompilationUnit unit = resolveCompilationUnit(source, library); | 147 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 148 // k |
| 145 Type2 intType = typeProvider.intType; | 149 Type2 intType = typeProvider.intType; |
| 146 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", Simp
leFormalParameter); | 150 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", Simp
leFormalParameter); |
| 147 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 151 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| 148 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", Sim
pleIdentifier); | 152 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", Sim
pleIdentifier); |
| 149 JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); | 153 JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); |
| 150 JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); | 154 JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); |
| 155 // v |
| 151 Type2 stringType = typeProvider.stringType; | 156 Type2 stringType = typeProvider.stringType; |
| 152 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); | 157 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); |
| 153 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 158 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 154 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); | 159 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); |
| 155 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 160 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 156 JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); | 161 JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { | 164 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { |
| 160 String code = EngineTestCase.createSource([ | 165 String code = EngineTestCase.createSource([ |
| 161 "class MyMap<K, V> {", | 166 "class MyMap<K, V> {", |
| 162 " forEach(f(K key, V value)) {}", | 167 " forEach(f(K key, V value)) {}", |
| 163 "}", | 168 "}", |
| 164 "f(MyMap<int, String> m) {", | 169 "f(MyMap<int, String> m) {", |
| 165 " var m2 = m;", | 170 " var m2 = m;", |
| 166 " m2.forEach((k, v) {});", | 171 " m2.forEach((k, v) {});", |
| 167 "}"]); | 172 "}"]); |
| 168 Source source = addSource(code); | 173 Source source = addSource(code); |
| 169 LibraryElement library = resolve(source); | 174 LibraryElement library = resolve(source); |
| 170 assertNoErrors(source); | 175 assertNoErrors(source); |
| 171 verify([source]); | 176 verify([source]); |
| 172 CompilationUnit unit = resolveCompilationUnit(source, library); | 177 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 178 // k |
| 173 Type2 intType = typeProvider.intType; | 179 Type2 intType = typeProvider.intType; |
| 174 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", Simp
leFormalParameter); | 180 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", Simp
leFormalParameter); |
| 175 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 181 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); |
| 182 // v |
| 176 Type2 stringType = typeProvider.stringType; | 183 Type2 stringType = typeProvider.stringType; |
| 177 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); | 184 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); |
| 178 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 185 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { | 188 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { |
| 182 String code = EngineTestCase.createSource([ | 189 String code = EngineTestCase.createSource([ |
| 183 "main() {", | 190 "main() {", |
| 184 " (f(String value)) {} ((v) {", | 191 " (f(String value)) {} ((v) {", |
| 185 " v;", | 192 " v;", |
| 186 " });", | 193 " });", |
| 187 "}"]); | 194 "}"]); |
| 188 Source source = addSource(code); | 195 Source source = addSource(code); |
| 189 LibraryElement library = resolve(source); | 196 LibraryElement library = resolve(source); |
| 190 assertNoErrors(source); | 197 assertNoErrors(source); |
| 191 verify([source]); | 198 verify([source]); |
| 192 CompilationUnit unit = resolveCompilationUnit(source, library); | 199 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 200 // v |
| 193 Type2 dynamicType = typeProvider.dynamicType; | 201 Type2 dynamicType = typeProvider.dynamicType; |
| 194 Type2 stringType = typeProvider.stringType; | 202 Type2 stringType = typeProvider.stringType; |
| 195 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Forma
lParameter); | 203 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Forma
lParameter); |
| 196 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 204 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 197 JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); | 205 JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); |
| 198 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); | 206 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); |
| 199 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 207 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 200 JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); | 208 JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); |
| 201 } | 209 } |
| 202 | 210 |
| 203 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { | 211 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { |
| 204 String code = EngineTestCase.createSource([ | 212 String code = EngineTestCase.createSource([ |
| 205 "class MyList {", | 213 "class MyList {", |
| 206 " forEach(f(Object value)) {}", | 214 " forEach(f(Object value)) {}", |
| 207 "}", | 215 "}", |
| 208 "f(MyList list) {", | 216 "f(MyList list) {", |
| 209 " list.forEach((int v) {", | 217 " list.forEach((int v) {", |
| 210 " v;", | 218 " v;", |
| 211 " });", | 219 " });", |
| 212 "}"]); | 220 "}"]); |
| 213 Source source = addSource(code); | 221 Source source = addSource(code); |
| 214 LibraryElement library = resolve(source); | 222 LibraryElement library = resolve(source); |
| 215 assertNoErrors(source); | 223 assertNoErrors(source); |
| 216 verify([source]); | 224 verify([source]); |
| 217 CompilationUnit unit = resolveCompilationUnit(source, library); | 225 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 226 // v |
| 218 Type2 intType = typeProvider.intType; | 227 Type2 intType = typeProvider.intType; |
| 219 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); | 228 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); |
| 220 JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); | 229 JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); |
| 221 JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); | 230 JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); |
| 222 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); | 231 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); |
| 223 JUnitTestCase.assertSame(intType, vIdentifier.staticType); | 232 JUnitTestCase.assertSame(intType, vIdentifier.staticType); |
| 224 JUnitTestCase.assertSame(null, vIdentifier.propagatedType); | 233 JUnitTestCase.assertSame(null, vIdentifier.propagatedType); |
| 225 } | 234 } |
| 226 | 235 |
| 227 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { | 236 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { |
| 228 String code = EngineTestCase.createSource([ | 237 String code = EngineTestCase.createSource([ |
| 229 "class MyList<E> {", | 238 "class MyList<E> {", |
| 230 " forEach(f(E value)) {}", | 239 " forEach(f(E value)) {}", |
| 231 "}", | 240 "}", |
| 232 "f(MyList<String> list) {", | 241 "f(MyList<String> list) {", |
| 233 " list.forEach((Object v) {", | 242 " list.forEach((Object v) {", |
| 234 " v;", | 243 " v;", |
| 235 " });", | 244 " });", |
| 236 "}"]); | 245 "}"]); |
| 237 Source source = addSource(code); | 246 Source source = addSource(code); |
| 238 LibraryElement library = resolve(source); | 247 LibraryElement library = resolve(source); |
| 239 assertNoErrors(source); | 248 assertNoErrors(source); |
| 240 verify([source]); | 249 verify([source]); |
| 241 CompilationUnit unit = resolveCompilationUnit(source, library); | 250 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 251 // v |
| 242 Type2 stringType = typeProvider.stringType; | 252 Type2 stringType = typeProvider.stringType; |
| 243 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); | 253 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", Simpl
eFormalParameter); |
| 244 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 254 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); |
| 245 JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.stat
icType); | 255 JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.stat
icType); |
| 246 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); | 256 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", Sim
pleIdentifier); |
| 247 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 257 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); |
| 248 } | 258 } |
| 249 | 259 |
| 250 void test_Future_then() { | 260 void test_Future_then() { |
| 251 String code = EngineTestCase.createSource([ | 261 String code = EngineTestCase.createSource([ |
| 252 "import 'dart:async';", | 262 "import 'dart:async';", |
| 253 "main(Future<int> firstFuture) {", | 263 "main(Future<int> firstFuture) {", |
| 254 " firstFuture.then((p1) {", | 264 " firstFuture.then((p1) {", |
| 255 " return 1.0;", | 265 " return 1.0;", |
| 256 " }).then((p2) {", | 266 " }).then((p2) {", |
| 257 " return new Future<String>.value('str');", | 267 " return new Future<String>.value('str');", |
| 258 " }).then((p3) {", | 268 " }).then((p3) {", |
| 259 " });", | 269 " });", |
| 260 "}"]); | 270 "}"]); |
| 261 Source source = addSource(code); | 271 Source source = addSource(code); |
| 262 LibraryElement library = resolve(source); | 272 LibraryElement library = resolve(source); |
| 263 assertNoErrors(source); | 273 assertNoErrors(source); |
| 264 verify([source]); | 274 verify([source]); |
| 265 CompilationUnit unit = resolveCompilationUnit(source, library); | 275 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 276 // p1 |
| 266 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", SimpleForm
alParameter); | 277 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", SimpleForm
alParameter); |
| 267 JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType)
; | 278 JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType)
; |
| 279 // p2 |
| 268 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", SimpleForm
alParameter); | 280 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", SimpleForm
alParameter); |
| 269 JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedTy
pe); | 281 JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedTy
pe); |
| 282 // p3 |
| 270 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", SimpleForm
alParameter); | 283 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", SimpleForm
alParameter); |
| 271 JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedTy
pe); | 284 JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedTy
pe); |
| 272 } | 285 } |
| 273 | 286 |
| 274 void test_initializer() { | 287 void test_initializer() { |
| 275 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0
;", " return v;", "}"])); | 288 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = 0
;", " return v;", "}"])); |
| 276 LibraryElement library = resolve(source); | 289 LibraryElement library = resolve(source); |
| 277 assertNoErrors(source); | 290 assertNoErrors(source); |
| 278 verify([source]); | 291 verify([source]); |
| 279 CompilationUnit unit = resolveCompilationUnit(source, library); | 292 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 280 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 293 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 281 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 294 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 282 NodeList<Statement> statements = body.block.statements; | 295 NodeList<Statement> statements = body.block.statements; |
| 296 // Type of 'v' in declaration. |
| 283 { | 297 { |
| 284 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; | 298 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; |
| 285 SimpleIdentifier variableName = statement.variables.variables[0].name; | 299 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 286 JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType
); | 300 JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType
); |
| 287 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 301 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); |
| 288 } | 302 } |
| 303 // Type of 'v' in reference. |
| 289 { | 304 { |
| 290 ReturnStatement statement = statements[1] as ReturnStatement; | 305 ReturnStatement statement = statements[1] as ReturnStatement; |
| 291 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 306 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 292 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 307 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); |
| 293 } | 308 } |
| 294 } | 309 } |
| 295 | 310 |
| 296 void test_initializer_dereference() { | 311 void test_initializer_dereference() { |
| 297 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = '
String';", " v.", "}"])); | 312 Source source = addSource(EngineTestCase.createSource(["f() {", " var v = '
String';", " v.", "}"])); |
| 298 LibraryElement library = resolve(source); | 313 LibraryElement library = resolve(source); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 " if (p is String) {", | 371 " if (p is String) {", |
| 357 " return p;", | 372 " return p;", |
| 358 " } else {", | 373 " } else {", |
| 359 " return null;", | 374 " return null;", |
| 360 " }", | 375 " }", |
| 361 "}"])); | 376 "}"])); |
| 362 LibraryElement library = resolve(source); | 377 LibraryElement library = resolve(source); |
| 363 assertNoErrors(source); | 378 assertNoErrors(source); |
| 364 verify([source]); | 379 verify([source]); |
| 365 CompilationUnit unit = resolveCompilationUnit(source, library); | 380 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 381 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().ge
t(0); |
| 382 // InterfaceType typeA = classA.getElement().getType(); |
| 366 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 383 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 367 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 384 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 368 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 385 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 369 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 386 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 370 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 387 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 371 JUnitTestCase.assertSame(null, variableName.propagatedType); | 388 JUnitTestCase.assertSame(null, variableName.propagatedType); |
| 372 } | 389 } |
| 373 | 390 |
| 374 void test_is_if_logicalAnd() { | 391 void test_is_if_logicalAnd() { |
| 375 Source source = addSource(EngineTestCase.createSource([ | 392 Source source = addSource(EngineTestCase.createSource([ |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 /** | 778 /** |
| 762 * @param code the code that assigns the value to the variable "v", no matter
how. We check that | 779 * @param code the code that assigns the value to the variable "v", no matter
how. We check that |
| 763 * "v" has expected static and propagated type. | 780 * "v" has expected static and propagated type. |
| 764 */ | 781 */ |
| 765 void check_propagatedReturnType(String code, Type2 expectedStaticType, Type2 e
xpectedPropagatedType) { | 782 void check_propagatedReturnType(String code, Type2 expectedStaticType, Type2 e
xpectedPropagatedType) { |
| 766 Source source = addSource(code); | 783 Source source = addSource(code); |
| 767 LibraryElement library = resolve(source); | 784 LibraryElement library = resolve(source); |
| 768 assertNoErrors(source); | 785 assertNoErrors(source); |
| 769 verify([source]); | 786 verify([source]); |
| 770 CompilationUnit unit = resolveCompilationUnit(source, library); | 787 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 788 // |
| 771 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = ", Si
mpleIdentifier); | 789 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = ", Si
mpleIdentifier); |
| 772 JUnitTestCase.assertSame(expectedStaticType, identifier.staticType); | 790 JUnitTestCase.assertSame(expectedStaticType, identifier.staticType); |
| 773 JUnitTestCase.assertSame(expectedPropagatedType, identifier.propagatedType); | 791 JUnitTestCase.assertSame(expectedPropagatedType, identifier.propagatedType); |
| 774 } | 792 } |
| 775 | 793 |
| 776 static dartSuite() { | 794 static dartSuite() { |
| 777 _ut.group('TypePropagationTest', () { | 795 _ut.group('TypePropagationTest', () { |
| 778 _ut.test('test_Future_then', () { | 796 _ut.test('test_Future_then', () { |
| 779 final __test = new TypePropagationTest(); | 797 final __test = new TypePropagationTest(); |
| 780 runJUnitTest(__test, __test.test_Future_then); | 798 runJUnitTest(__test, __test.test_Future_then); |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 "library lib1;", | 1618 "library lib1;", |
| 1601 "class A {}", | 1619 "class A {}", |
| 1602 "@deprecated", | 1620 "@deprecated", |
| 1603 "class B {}"])); | 1621 "class B {}"])); |
| 1604 resolve(source); | 1622 resolve(source); |
| 1605 assertNoErrors(source); | 1623 assertNoErrors(source); |
| 1606 verify([source]); | 1624 verify([source]); |
| 1607 } | 1625 } |
| 1608 | 1626 |
| 1609 void test_duplicateDefinition_emptyName() { | 1627 void test_duplicateDefinition_emptyName() { |
| 1628 // Note: This code has two FunctionElements '() {}' with an empty name, this
tests that the |
| 1629 // empty string is not put into the scope (more than once). |
| 1610 Source source = addSource(EngineTestCase.createSource([ | 1630 Source source = addSource(EngineTestCase.createSource([ |
| 1611 "Map _globalMap = {", | 1631 "Map _globalMap = {", |
| 1612 " 'a' : () {},", | 1632 " 'a' : () {},", |
| 1613 " 'b' : () {}", | 1633 " 'b' : () {}", |
| 1614 "};"])); | 1634 "};"])); |
| 1615 resolve(source); | 1635 resolve(source); |
| 1616 assertNoErrors(source); | 1636 assertNoErrors(source); |
| 1617 verify([source]); | 1637 verify([source]); |
| 1618 } | 1638 } |
| 1619 | 1639 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2227 } | 2247 } |
| 2228 | 2248 |
| 2229 void test_instanceMethodNameCollidesWithSuperclassStatic_method() { | 2249 void test_instanceMethodNameCollidesWithSuperclassStatic_method() { |
| 2230 Source source = addSource(EngineTestCase.createSource([ | 2250 Source source = addSource(EngineTestCase.createSource([ |
| 2231 "import 'lib.dart';", | 2251 "import 'lib.dart';", |
| 2232 "class B extends A {", | 2252 "class B extends A {", |
| 2233 " _m() {}", | 2253 " _m() {}", |
| 2234 "}"])); | 2254 "}"])); |
| 2235 addSource2("/lib.dart", EngineTestCase.createSource(["library L;", "class A
{", " static _m() {}", "}"])); | 2255 addSource2("/lib.dart", EngineTestCase.createSource(["library L;", "class A
{", " static _m() {}", "}"])); |
| 2236 resolve(source); | 2256 resolve(source); |
| 2237 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); | 2257 assertErrors(source, []); |
| 2238 verify([source]); | 2258 verify([source]); |
| 2239 } | 2259 } |
| 2240 | 2260 |
| 2241 void test_invalidAnnotation_constantVariable_field() { | 2261 void test_invalidAnnotation_constantVariable_field() { |
| 2242 Source source = addSource(EngineTestCase.createSource(["@A.C", "class A {",
" static const C = 0;", "}"])); | 2262 Source source = addSource(EngineTestCase.createSource(["@A.C", "class A {",
" static const C = 0;", "}"])); |
| 2243 resolve(source); | 2263 resolve(source); |
| 2244 assertNoErrors(source); | 2264 assertNoErrors(source); |
| 2245 verify([source]); | 2265 verify([source]); |
| 2246 } | 2266 } |
| 2247 | 2267 |
| (...skipping 5145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7393 verify([source]); | 7413 verify([source]); |
| 7394 } | 7414 } |
| 7395 | 7415 |
| 7396 void fail_missingReturn_method() { | 7416 void fail_missingReturn_method() { |
| 7397 Source source = addSource(EngineTestCase.createSource(["class A {", " int m
() {}", "}"])); | 7417 Source source = addSource(EngineTestCase.createSource(["class A {", " int m
() {}", "}"])); |
| 7398 resolve(source); | 7418 resolve(source); |
| 7399 assertErrors(source, [HintCode.MISSING_RETURN]); | 7419 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 7400 verify([source]); | 7420 verify([source]); |
| 7401 } | 7421 } |
| 7402 | 7422 |
| 7423 void fail_overriddingPrivateMember_getter() { |
| 7424 Source source = addSource(EngineTestCase.createSource([ |
| 7425 "import 'lib1.dart';", |
| 7426 "class B extends A {", |
| 7427 " get _g => 0;", |
| 7428 "}"])); |
| 7429 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " get _g => 0;", "}"])); |
| 7430 resolve(source); |
| 7431 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); |
| 7432 verify([source, source2]); |
| 7433 } |
| 7434 |
| 7435 void fail_overriddingPrivateMember_method() { |
| 7436 Source source = addSource(EngineTestCase.createSource([ |
| 7437 "import 'lib1.dart';", |
| 7438 "class B extends A {", |
| 7439 " _m(int x) => 0;", |
| 7440 "}"])); |
| 7441 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " _m(int x) => 0;", "}"])); |
| 7442 resolve(source); |
| 7443 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); |
| 7444 verify([source, source2]); |
| 7445 } |
| 7446 |
| 7447 void fail_overriddingPrivateMember_method2() { |
| 7448 Source source = addSource(EngineTestCase.createSource([ |
| 7449 "import 'lib1.dart';", |
| 7450 "class B extends A {}", |
| 7451 "class C extends B {", |
| 7452 " _m(int x) => 0;", |
| 7453 "}"])); |
| 7454 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " _m(int x) => 0;", "}"])); |
| 7455 resolve(source); |
| 7456 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); |
| 7457 verify([source, source2]); |
| 7458 } |
| 7459 |
| 7460 void fail_overriddingPrivateMember_setter() { |
| 7461 Source source = addSource(EngineTestCase.createSource([ |
| 7462 "import 'lib1.dart';", |
| 7463 "class B extends A {", |
| 7464 " set _s(int x) {}", |
| 7465 "}"])); |
| 7466 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " set _s(int x) {}", "}"])); |
| 7467 resolve(source); |
| 7468 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); |
| 7469 verify([source, source2]); |
| 7470 } |
| 7471 |
| 7403 void fail_overrideEqualsButNotHashCode() { | 7472 void fail_overrideEqualsButNotHashCode() { |
| 7404 Source source = addSource(EngineTestCase.createSource(["class A {", " bool
operator ==(x) {}", "}"])); | 7473 Source source = addSource(EngineTestCase.createSource(["class A {", " bool
operator ==(x) {}", "}"])); |
| 7405 resolve(source); | 7474 resolve(source); |
| 7406 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); | 7475 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); |
| 7407 verify([source]); | 7476 verify([source]); |
| 7408 } | 7477 } |
| 7409 | 7478 |
| 7410 void test_deadCode_deadBlock_conditionalElse() { | 7479 void test_deadCode_deadBlock_conditionalElse() { |
| 7411 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? 1
: 2;", "}"])); | 7480 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? 1
: 2;", "}"])); |
| 7412 resolve(source); | 7481 resolve(source); |
| 7413 assertErrors(source, [HintCode.DEAD_CODE]); | 7482 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7414 verify([source]); | 7483 verify([source]); |
| 7415 } | 7484 } |
| 7416 | 7485 |
| 7417 void test_deadCode_deadBlock_conditionalElse_nested() { | 7486 void test_deadCode_deadBlock_conditionalElse_nested() { |
| 7487 // test that a dead else-statement can't generate additional violations |
| 7418 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? tr
ue : false && false;", "}"])); | 7488 Source source = addSource(EngineTestCase.createSource(["f() {", " true ? tr
ue : false && false;", "}"])); |
| 7419 resolve(source); | 7489 resolve(source); |
| 7420 assertErrors(source, [HintCode.DEAD_CODE]); | 7490 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7421 verify([source]); | 7491 verify([source]); |
| 7422 } | 7492 } |
| 7423 | 7493 |
| 7424 void test_deadCode_deadBlock_conditionalIf() { | 7494 void test_deadCode_deadBlock_conditionalIf() { |
| 7425 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? 1
: 2;", "}"])); | 7495 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? 1
: 2;", "}"])); |
| 7426 resolve(source); | 7496 resolve(source); |
| 7427 assertErrors(source, [HintCode.DEAD_CODE]); | 7497 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7428 verify([source]); | 7498 verify([source]); |
| 7429 } | 7499 } |
| 7430 | 7500 |
| 7431 void test_deadCode_deadBlock_conditionalIf_nested() { | 7501 void test_deadCode_deadBlock_conditionalIf_nested() { |
| 7502 // test that a dead then-statement can't generate additional violations |
| 7432 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? f
alse && false : true;", "}"])); | 7503 Source source = addSource(EngineTestCase.createSource(["f() {", " false ? f
alse && false : true;", "}"])); |
| 7433 resolve(source); | 7504 resolve(source); |
| 7434 assertErrors(source, [HintCode.DEAD_CODE]); | 7505 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7435 verify([source]); | 7506 verify([source]); |
| 7436 } | 7507 } |
| 7437 | 7508 |
| 7438 void test_deadCode_deadBlock_else() { | 7509 void test_deadCode_deadBlock_else() { |
| 7439 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {}", "}"])); | 7510 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {}", "}"])); |
| 7440 resolve(source); | 7511 resolve(source); |
| 7441 assertErrors(source, [HintCode.DEAD_CODE]); | 7512 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7442 verify([source]); | 7513 verify([source]); |
| 7443 } | 7514 } |
| 7444 | 7515 |
| 7445 void test_deadCode_deadBlock_else_nested() { | 7516 void test_deadCode_deadBlock_else_nested() { |
| 7517 // test that a dead else-statement can't generate additional violations |
| 7446 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {if (false) {}}", "}"])); | 7518 Source source = addSource(EngineTestCase.createSource(["f() {", " if(true)
{} else {if (false) {}}", "}"])); |
| 7447 resolve(source); | 7519 resolve(source); |
| 7448 assertErrors(source, [HintCode.DEAD_CODE]); | 7520 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7449 verify([source]); | 7521 verify([source]); |
| 7450 } | 7522 } |
| 7451 | 7523 |
| 7452 void test_deadCode_deadBlock_if() { | 7524 void test_deadCode_deadBlock_if() { |
| 7453 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{}", "}"])); | 7525 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{}", "}"])); |
| 7454 resolve(source); | 7526 resolve(source); |
| 7455 assertErrors(source, [HintCode.DEAD_CODE]); | 7527 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7456 verify([source]); | 7528 verify([source]); |
| 7457 } | 7529 } |
| 7458 | 7530 |
| 7459 void test_deadCode_deadBlock_if_nested() { | 7531 void test_deadCode_deadBlock_if_nested() { |
| 7532 // test that a dead then-statement can't generate additional violations |
| 7460 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{if(false) {}}", "}"])); | 7533 Source source = addSource(EngineTestCase.createSource(["f() {", " if(false)
{if(false) {}}", "}"])); |
| 7461 resolve(source); | 7534 resolve(source); |
| 7462 assertErrors(source, [HintCode.DEAD_CODE]); | 7535 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7463 verify([source]); | 7536 verify([source]); |
| 7464 } | 7537 } |
| 7465 | 7538 |
| 7466 void test_deadCode_deadBlock_while() { | 7539 void test_deadCode_deadBlock_while() { |
| 7467 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {}", "}"])); | 7540 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {}", "}"])); |
| 7468 resolve(source); | 7541 resolve(source); |
| 7469 assertErrors(source, [HintCode.DEAD_CODE]); | 7542 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7470 verify([source]); | 7543 verify([source]); |
| 7471 } | 7544 } |
| 7472 | 7545 |
| 7473 void test_deadCode_deadBlock_while_nested() { | 7546 void test_deadCode_deadBlock_while_nested() { |
| 7547 // test that a dead while body can't generate additional violations |
| 7474 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {if(false) {}}", "}"])); | 7548 Source source = addSource(EngineTestCase.createSource(["f() {", " while(fal
se) {if(false) {}}", "}"])); |
| 7475 resolve(source); | 7549 resolve(source); |
| 7476 assertErrors(source, [HintCode.DEAD_CODE]); | 7550 assertErrors(source, [HintCode.DEAD_CODE]); |
| 7477 verify([source]); | 7551 verify([source]); |
| 7478 } | 7552 } |
| 7479 | 7553 |
| 7480 void test_deadCode_deadCatch_catchFollowingCatch() { | 7554 void test_deadCode_deadCatch_catchFollowingCatch() { |
| 7481 Source source = addSource(EngineTestCase.createSource([ | 7555 Source source = addSource(EngineTestCase.createSource([ |
| 7482 "class A {}", | 7556 "class A {}", |
| 7483 "f() {", | 7557 "f() {", |
| 7484 " try {} catch (e) {} catch (e) {}", | 7558 " try {} catch (e) {} catch (e) {}", |
| 7485 "}"])); | 7559 "}"])); |
| 7486 resolve(source); | 7560 resolve(source); |
| 7487 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 7561 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 7488 verify([source]); | 7562 verify([source]); |
| 7489 } | 7563 } |
| 7490 | 7564 |
| 7491 void test_deadCode_deadCatch_catchFollowingCatch_nested() { | 7565 void test_deadCode_deadCatch_catchFollowingCatch_nested() { |
| 7566 // test that a dead catch clause can't generate additional violations |
| 7492 Source source = addSource(EngineTestCase.createSource([ | 7567 Source source = addSource(EngineTestCase.createSource([ |
| 7493 "class A {}", | 7568 "class A {}", |
| 7494 "f() {", | 7569 "f() {", |
| 7495 " try {} catch (e) {} catch (e) {if(false) {}}", | 7570 " try {} catch (e) {} catch (e) {if(false) {}}", |
| 7496 "}"])); | 7571 "}"])); |
| 7497 resolve(source); | 7572 resolve(source); |
| 7498 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 7573 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 7499 verify([source]); | 7574 verify([source]); |
| 7500 } | 7575 } |
| 7501 | 7576 |
| 7502 void test_deadCode_deadCatch_catchFollowingCatch_object() { | 7577 void test_deadCode_deadCatch_catchFollowingCatch_object() { |
| 7503 Source source = addSource(EngineTestCase.createSource([ | 7578 Source source = addSource(EngineTestCase.createSource([ |
| 7504 "f() {", | 7579 "f() {", |
| 7505 " try {} on Object catch (e) {} catch (e) {}", | 7580 " try {} on Object catch (e) {} catch (e) {}", |
| 7506 "}"])); | 7581 "}"])); |
| 7507 resolve(source); | 7582 resolve(source); |
| 7508 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 7583 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 7509 verify([source]); | 7584 verify([source]); |
| 7510 } | 7585 } |
| 7511 | 7586 |
| 7512 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { | 7587 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { |
| 7588 // test that a dead catch clause can't generate additional violations |
| 7513 Source source = addSource(EngineTestCase.createSource([ | 7589 Source source = addSource(EngineTestCase.createSource([ |
| 7514 "f() {", | 7590 "f() {", |
| 7515 " try {} on Object catch (e) {} catch (e) {if(false) {}}", | 7591 " try {} on Object catch (e) {} catch (e) {if(false) {}}", |
| 7516 "}"])); | 7592 "}"])); |
| 7517 resolve(source); | 7593 resolve(source); |
| 7518 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 7594 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 7519 verify([source]); | 7595 verify([source]); |
| 7520 } | 7596 } |
| 7521 | 7597 |
| 7522 void test_deadCode_deadCatch_onCatchSubtype() { | 7598 void test_deadCode_deadCatch_onCatchSubtype() { |
| 7523 Source source = addSource(EngineTestCase.createSource([ | 7599 Source source = addSource(EngineTestCase.createSource([ |
| 7524 "class A {}", | 7600 "class A {}", |
| 7525 "class B extends A {}", | 7601 "class B extends A {}", |
| 7526 "f() {", | 7602 "f() {", |
| 7527 " try {} on A catch (e) {} on B catch (e) {}", | 7603 " try {} on A catch (e) {} on B catch (e) {}", |
| 7528 "}"])); | 7604 "}"])); |
| 7529 resolve(source); | 7605 resolve(source); |
| 7530 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 7606 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 7531 verify([source]); | 7607 verify([source]); |
| 7532 } | 7608 } |
| 7533 | 7609 |
| 7534 void test_deadCode_deadCatch_onCatchSubtype_nested() { | 7610 void test_deadCode_deadCatch_onCatchSubtype_nested() { |
| 7611 // test that a dead catch clause can't generate additional violations |
| 7535 Source source = addSource(EngineTestCase.createSource([ | 7612 Source source = addSource(EngineTestCase.createSource([ |
| 7536 "class A {}", | 7613 "class A {}", |
| 7537 "class B extends A {}", | 7614 "class B extends A {}", |
| 7538 "f() {", | 7615 "f() {", |
| 7539 " try {} on A catch (e) {} on B catch (e) {if(false) {}}", | 7616 " try {} on A catch (e) {} on B catch (e) {if(false) {}}", |
| 7540 "}"])); | 7617 "}"])); |
| 7541 resolve(source); | 7618 resolve(source); |
| 7542 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 7619 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 7543 verify([source]); | 7620 verify([source]); |
| 7544 } | 7621 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7822 } | 7899 } |
| 7823 | 7900 |
| 7824 void test_divisionOptimization_int() { | 7901 void test_divisionOptimization_int() { |
| 7825 Source source = addSource(EngineTestCase.createSource(["f(int x, int y) {",
" var v = (x / y).toInt();", "}"])); | 7902 Source source = addSource(EngineTestCase.createSource(["f(int x, int y) {",
" var v = (x / y).toInt();", "}"])); |
| 7826 resolve(source); | 7903 resolve(source); |
| 7827 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 7904 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 7828 verify([source]); | 7905 verify([source]); |
| 7829 } | 7906 } |
| 7830 | 7907 |
| 7831 void test_divisionOptimization_propagatedType() { | 7908 void test_divisionOptimization_propagatedType() { |
| 7909 // Tests the propagated type information of the '/' method |
| 7832 Source source = addSource(EngineTestCase.createSource([ | 7910 Source source = addSource(EngineTestCase.createSource([ |
| 7833 "f(x, y) {", | 7911 "f(x, y) {", |
| 7834 " x = 1;", | 7912 " x = 1;", |
| 7835 " y = 1;", | 7913 " y = 1;", |
| 7836 " var v = (x / y).toInt();", | 7914 " var v = (x / y).toInt();", |
| 7837 "}"])); | 7915 "}"])); |
| 7838 resolve(source); | 7916 resolve(source); |
| 7839 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 7917 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 7840 verify([source]); | 7918 verify([source]); |
| 7841 } | 7919 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7894 verify([source]); | 7972 verify([source]); |
| 7895 } | 7973 } |
| 7896 | 7974 |
| 7897 void test_isNotDouble() { | 7975 void test_isNotDouble() { |
| 7898 Source source = addSource(EngineTestCase.createSource(["var v = 1 is! double
;"])); | 7976 Source source = addSource(EngineTestCase.createSource(["var v = 1 is! double
;"])); |
| 7899 resolve(source); | 7977 resolve(source); |
| 7900 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); | 7978 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); |
| 7901 verify([source]); | 7979 verify([source]); |
| 7902 } | 7980 } |
| 7903 | 7981 |
| 7904 void test_overriddingPrivateMember_getter() { | |
| 7905 Source source = addSource(EngineTestCase.createSource([ | |
| 7906 "import 'lib1.dart';", | |
| 7907 "class B extends A {", | |
| 7908 " get _g => 0;", | |
| 7909 "}"])); | |
| 7910 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " get _g => 0;", "}"])); | |
| 7911 resolve(source); | |
| 7912 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); | |
| 7913 verify([source, source2]); | |
| 7914 } | |
| 7915 | |
| 7916 void test_overriddingPrivateMember_method() { | |
| 7917 Source source = addSource(EngineTestCase.createSource([ | |
| 7918 "import 'lib1.dart';", | |
| 7919 "class B extends A {", | |
| 7920 " _m(int x) => 0;", | |
| 7921 "}"])); | |
| 7922 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " _m(int x) => 0;", "}"])); | |
| 7923 resolve(source); | |
| 7924 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); | |
| 7925 verify([source, source2]); | |
| 7926 } | |
| 7927 | |
| 7928 void test_overriddingPrivateMember_method2() { | |
| 7929 Source source = addSource(EngineTestCase.createSource([ | |
| 7930 "import 'lib1.dart';", | |
| 7931 "class B extends A {}", | |
| 7932 "class C extends B {", | |
| 7933 " _m(int x) => 0;", | |
| 7934 "}"])); | |
| 7935 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " _m(int x) => 0;", "}"])); | |
| 7936 resolve(source); | |
| 7937 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); | |
| 7938 verify([source, source2]); | |
| 7939 } | |
| 7940 | |
| 7941 void test_overriddingPrivateMember_setter() { | |
| 7942 Source source = addSource(EngineTestCase.createSource([ | |
| 7943 "import 'lib1.dart';", | |
| 7944 "class B extends A {", | |
| 7945 " set _s(int x) {}", | |
| 7946 "}"])); | |
| 7947 Source source2 = addSource2("/lib1.dart", EngineTestCase.createSource(["libr
ary lib1;", "class A {", " set _s(int x) {}", "}"])); | |
| 7948 resolve(source); | |
| 7949 assertErrors(source, [HintCode.OVERRIDDING_PRIVATE_MEMBER]); | |
| 7950 verify([source, source2]); | |
| 7951 } | |
| 7952 | |
| 7953 void test_typeCheck_type_is_Null() { | 7982 void test_typeCheck_type_is_Null() { |
| 7954 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is Null;", "}"])); | 7983 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is Null;", "}"])); |
| 7955 resolve(source); | 7984 resolve(source); |
| 7956 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); | 7985 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); |
| 7957 verify([source]); | 7986 verify([source]); |
| 7958 } | 7987 } |
| 7959 | 7988 |
| 7960 void test_typeCheck_type_not_Null() { | 7989 void test_typeCheck_type_not_Null() { |
| 7961 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is! Null;", "}"])); | 7990 Source source = addSource(EngineTestCase.createSource(["m(i) {", " bool b =
i is! Null;", "}"])); |
| 7962 resolve(source); | 7991 resolve(source); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8379 runJUnitTest(__test, __test.test_duplicateImport3); | 8408 runJUnitTest(__test, __test.test_duplicateImport3); |
| 8380 }); | 8409 }); |
| 8381 _ut.test('test_isDouble', () { | 8410 _ut.test('test_isDouble', () { |
| 8382 final __test = new HintCodeTest(); | 8411 final __test = new HintCodeTest(); |
| 8383 runJUnitTest(__test, __test.test_isDouble); | 8412 runJUnitTest(__test, __test.test_isDouble); |
| 8384 }); | 8413 }); |
| 8385 _ut.test('test_isNotDouble', () { | 8414 _ut.test('test_isNotDouble', () { |
| 8386 final __test = new HintCodeTest(); | 8415 final __test = new HintCodeTest(); |
| 8387 runJUnitTest(__test, __test.test_isNotDouble); | 8416 runJUnitTest(__test, __test.test_isNotDouble); |
| 8388 }); | 8417 }); |
| 8389 _ut.test('test_overriddingPrivateMember_getter', () { | |
| 8390 final __test = new HintCodeTest(); | |
| 8391 runJUnitTest(__test, __test.test_overriddingPrivateMember_getter); | |
| 8392 }); | |
| 8393 _ut.test('test_overriddingPrivateMember_method', () { | |
| 8394 final __test = new HintCodeTest(); | |
| 8395 runJUnitTest(__test, __test.test_overriddingPrivateMember_method); | |
| 8396 }); | |
| 8397 _ut.test('test_overriddingPrivateMember_method2', () { | |
| 8398 final __test = new HintCodeTest(); | |
| 8399 runJUnitTest(__test, __test.test_overriddingPrivateMember_method2); | |
| 8400 }); | |
| 8401 _ut.test('test_overriddingPrivateMember_setter', () { | |
| 8402 final __test = new HintCodeTest(); | |
| 8403 runJUnitTest(__test, __test.test_overriddingPrivateMember_setter); | |
| 8404 }); | |
| 8405 _ut.test('test_typeCheck_type_is_Null', () { | 8418 _ut.test('test_typeCheck_type_is_Null', () { |
| 8406 final __test = new HintCodeTest(); | 8419 final __test = new HintCodeTest(); |
| 8407 runJUnitTest(__test, __test.test_typeCheck_type_is_Null); | 8420 runJUnitTest(__test, __test.test_typeCheck_type_is_Null); |
| 8408 }); | 8421 }); |
| 8409 _ut.test('test_typeCheck_type_not_Null', () { | 8422 _ut.test('test_typeCheck_type_not_Null', () { |
| 8410 final __test = new HintCodeTest(); | 8423 final __test = new HintCodeTest(); |
| 8411 runJUnitTest(__test, __test.test_typeCheck_type_not_Null); | 8424 runJUnitTest(__test, __test.test_typeCheck_type_not_Null); |
| 8412 }); | 8425 }); |
| 8413 _ut.test('test_undefinedGetter', () { | 8426 _ut.test('test_undefinedGetter', () { |
| 8414 final __test = new HintCodeTest(); | 8427 final __test = new HintCodeTest(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8555 void fail_visitMethodDeclaration() { | 8568 void fail_visitMethodDeclaration() { |
| 8556 JUnitTestCase.fail("Not yet tested"); | 8569 JUnitTestCase.fail("Not yet tested"); |
| 8557 _listener.assertNoErrors(); | 8570 _listener.assertNoErrors(); |
| 8558 } | 8571 } |
| 8559 | 8572 |
| 8560 void fail_visitVariableDeclaration() { | 8573 void fail_visitVariableDeclaration() { |
| 8561 JUnitTestCase.fail("Not yet tested"); | 8574 JUnitTestCase.fail("Not yet tested"); |
| 8562 ClassElement type = ElementFactory.classElement2("A", []); | 8575 ClassElement type = ElementFactory.classElement2("A", []); |
| 8563 VariableDeclaration node = ASTFactory.variableDeclaration("a"); | 8576 VariableDeclaration node = ASTFactory.variableDeclaration("a"); |
| 8564 ASTFactory.variableDeclarationList(null, ASTFactory.typeName(type, []), [nod
e]); | 8577 ASTFactory.variableDeclarationList(null, ASTFactory.typeName(type, []), [nod
e]); |
| 8578 //resolve(node); |
| 8565 JUnitTestCase.assertSame(type.type, node.name.staticType); | 8579 JUnitTestCase.assertSame(type.type, node.name.staticType); |
| 8566 _listener.assertNoErrors(); | 8580 _listener.assertNoErrors(); |
| 8567 } | 8581 } |
| 8568 | 8582 |
| 8569 void setUp() { | 8583 void setUp() { |
| 8570 _listener = new GatheringErrorListener(); | 8584 _listener = new GatheringErrorListener(); |
| 8571 SourceFactory factory = new SourceFactory.con2([new FileUriResolver()]); | 8585 SourceFactory factory = new SourceFactory.con2([new FileUriResolver()]); |
| 8572 AnalysisContextImpl context = new AnalysisContextImpl(); | 8586 AnalysisContextImpl context = new AnalysisContextImpl(); |
| 8573 context.sourceFactory = factory; | 8587 context.sourceFactory = factory; |
| 8574 Source librarySource = new FileBasedSource.con1(factory.contentCache, FileUt
ilities2.createFile("/lib.dart")); | 8588 Source librarySource = new FileBasedSource.con1(factory.contentCache, FileUt
ilities2.createFile("/lib.dart")); |
| 8575 _library = new Library(context, _listener, librarySource); | 8589 _library = new Library(context, _listener, librarySource); |
| 8576 LibraryElementImpl element = new LibraryElementImpl(context, ASTFactory.libr
aryIdentifier2(["lib"])); | 8590 LibraryElementImpl element = new LibraryElementImpl(context, ASTFactory.libr
aryIdentifier2(["lib"])); |
| 8577 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart")
; | 8591 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart")
; |
| 8578 _library.libraryElement = element; | 8592 _library.libraryElement = element; |
| 8579 _typeProvider = new TestTypeProvider(); | 8593 _typeProvider = new TestTypeProvider(); |
| 8580 _visitor = new TypeResolverVisitor.con1(_library, librarySource, _typeProvid
er); | 8594 _visitor = new TypeResolverVisitor.con1(_library, librarySource, _typeProvid
er); |
| 8581 } | 8595 } |
| 8582 | 8596 |
| 8583 void test_visitCatchClause_exception() { | 8597 void test_visitCatchClause_exception() { |
| 8598 // catch (e) |
| 8584 CatchClause clause = ASTFactory.catchClause("e", []); | 8599 CatchClause clause = ASTFactory.catchClause("e", []); |
| 8585 SimpleIdentifier exceptionParameter = clause.exceptionParameter; | 8600 SimpleIdentifier exceptionParameter = clause.exceptionParameter; |
| 8586 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); | 8601 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); |
| 8587 resolve(clause, _typeProvider.dynamicType, null, []); | 8602 resolve(clause, _typeProvider.dynamicType, null, []); |
| 8588 _listener.assertNoErrors(); | 8603 _listener.assertNoErrors(); |
| 8589 } | 8604 } |
| 8590 | 8605 |
| 8591 void test_visitCatchClause_exception_stackTrace() { | 8606 void test_visitCatchClause_exception_stackTrace() { |
| 8607 // catch (e, s) |
| 8592 CatchClause clause = ASTFactory.catchClause2("e", "s", []); | 8608 CatchClause clause = ASTFactory.catchClause2("e", "s", []); |
| 8593 SimpleIdentifier exceptionParameter = clause.exceptionParameter; | 8609 SimpleIdentifier exceptionParameter = clause.exceptionParameter; |
| 8594 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); | 8610 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); |
| 8595 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; | 8611 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; |
| 8596 stackTraceParameter.staticElement = new LocalVariableElementImpl(stackTraceP
arameter); | 8612 stackTraceParameter.staticElement = new LocalVariableElementImpl(stackTraceP
arameter); |
| 8597 resolve(clause, _typeProvider.dynamicType, _typeProvider.stackTraceType, [])
; | 8613 resolve(clause, _typeProvider.dynamicType, _typeProvider.stackTraceType, [])
; |
| 8598 _listener.assertNoErrors(); | 8614 _listener.assertNoErrors(); |
| 8599 } | 8615 } |
| 8600 | 8616 |
| 8601 void test_visitCatchClause_on_exception() { | 8617 void test_visitCatchClause_on_exception() { |
| 8618 // on E catch (e) |
| 8602 ClassElement exceptionElement = ElementFactory.classElement2("E", []); | 8619 ClassElement exceptionElement = ElementFactory.classElement2("E", []); |
| 8603 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []); | 8620 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []); |
| 8604 CatchClause clause = ASTFactory.catchClause4(exceptionType, "e", []); | 8621 CatchClause clause = ASTFactory.catchClause4(exceptionType, "e", []); |
| 8605 SimpleIdentifier exceptionParameter = clause.exceptionParameter; | 8622 SimpleIdentifier exceptionParameter = clause.exceptionParameter; |
| 8606 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); | 8623 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); |
| 8607 resolve(clause, exceptionElement.type, null, [exceptionElement]); | 8624 resolve(clause, exceptionElement.type, null, [exceptionElement]); |
| 8608 _listener.assertNoErrors(); | 8625 _listener.assertNoErrors(); |
| 8609 } | 8626 } |
| 8610 | 8627 |
| 8611 void test_visitCatchClause_on_exception_stackTrace() { | 8628 void test_visitCatchClause_on_exception_stackTrace() { |
| 8629 // on E catch (e, s) |
| 8612 ClassElement exceptionElement = ElementFactory.classElement2("E", []); | 8630 ClassElement exceptionElement = ElementFactory.classElement2("E", []); |
| 8613 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []); | 8631 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []); |
| 8614 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement; | 8632 (exceptionType.name as SimpleIdentifier).staticElement = exceptionElement; |
| 8615 CatchClause clause = ASTFactory.catchClause5(exceptionType, "e", "s", []); | 8633 CatchClause clause = ASTFactory.catchClause5(exceptionType, "e", "s", []); |
| 8616 SimpleIdentifier exceptionParameter = clause.exceptionParameter; | 8634 SimpleIdentifier exceptionParameter = clause.exceptionParameter; |
| 8617 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); | 8635 exceptionParameter.staticElement = new LocalVariableElementImpl(exceptionPar
ameter); |
| 8618 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; | 8636 SimpleIdentifier stackTraceParameter = clause.stackTraceParameter; |
| 8619 stackTraceParameter.staticElement = new LocalVariableElementImpl(stackTraceP
arameter); | 8637 stackTraceParameter.staticElement = new LocalVariableElementImpl(stackTraceP
arameter); |
| 8620 resolve(clause, exceptionElement.type, _typeProvider.stackTraceType, [except
ionElement]); | 8638 resolve(clause, exceptionElement.type, _typeProvider.stackTraceType, [except
ionElement]); |
| 8621 _listener.assertNoErrors(); | 8639 _listener.assertNoErrors(); |
| 8622 } | 8640 } |
| 8623 | 8641 |
| 8624 void test_visitClassDeclaration() { | 8642 void test_visitClassDeclaration() { |
| 8643 // class A extends B with C implements D {} |
| 8625 ClassElement elementA = ElementFactory.classElement2("A", []); | 8644 ClassElement elementA = ElementFactory.classElement2("A", []); |
| 8626 ClassElement elementB = ElementFactory.classElement2("B", []); | 8645 ClassElement elementB = ElementFactory.classElement2("B", []); |
| 8627 ClassElement elementC = ElementFactory.classElement2("C", []); | 8646 ClassElement elementC = ElementFactory.classElement2("C", []); |
| 8628 ClassElement elementD = ElementFactory.classElement2("D", []); | 8647 ClassElement elementD = ElementFactory.classElement2("D", []); |
| 8629 ExtendsClause extendsClause = ASTFactory.extendsClause(ASTFactory.typeName(e
lementB, [])); | 8648 ExtendsClause extendsClause = ASTFactory.extendsClause(ASTFactory.typeName(e
lementB, [])); |
| 8630 WithClause withClause = ASTFactory.withClause([ASTFactory.typeName(elementC,
[])]); | 8649 WithClause withClause = ASTFactory.withClause([ASTFactory.typeName(elementC,
[])]); |
| 8631 ImplementsClause implementsClause = ASTFactory.implementsClause([ASTFactory.
typeName(elementD, [])]); | 8650 ImplementsClause implementsClause = ASTFactory.implementsClause([ASTFactory.
typeName(elementD, [])]); |
| 8632 ClassDeclaration declaration = ASTFactory.classDeclaration(null, "A", null,
extendsClause, withClause, implementsClause, []); | 8651 ClassDeclaration declaration = ASTFactory.classDeclaration(null, "A", null,
extendsClause, withClause, implementsClause, []); |
| 8633 declaration.name.staticElement = elementA; | 8652 declaration.name.staticElement = elementA; |
| 8634 resolveNode(declaration, [elementA, elementB, elementC, elementD]); | 8653 resolveNode(declaration, [elementA, elementB, elementC, elementD]); |
| 8635 JUnitTestCase.assertSame(elementB.type, elementA.supertype); | 8654 JUnitTestCase.assertSame(elementB.type, elementA.supertype); |
| 8636 List<InterfaceType> mixins = elementA.mixins; | 8655 List<InterfaceType> mixins = elementA.mixins; |
| 8637 EngineTestCase.assertLength(1, mixins); | 8656 EngineTestCase.assertLength(1, mixins); |
| 8638 JUnitTestCase.assertSame(elementC.type, mixins[0]); | 8657 JUnitTestCase.assertSame(elementC.type, mixins[0]); |
| 8639 List<InterfaceType> interfaces = elementA.interfaces; | 8658 List<InterfaceType> interfaces = elementA.interfaces; |
| 8640 EngineTestCase.assertLength(1, interfaces); | 8659 EngineTestCase.assertLength(1, interfaces); |
| 8641 JUnitTestCase.assertSame(elementD.type, interfaces[0]); | 8660 JUnitTestCase.assertSame(elementD.type, interfaces[0]); |
| 8642 _listener.assertNoErrors(); | 8661 _listener.assertNoErrors(); |
| 8643 } | 8662 } |
| 8644 | 8663 |
| 8645 void test_visitClassTypeAlias() { | 8664 void test_visitClassTypeAlias() { |
| 8665 // class A = B with C implements D; |
| 8646 ClassElement elementA = ElementFactory.classElement2("A", []); | 8666 ClassElement elementA = ElementFactory.classElement2("A", []); |
| 8647 ClassElement elementB = ElementFactory.classElement2("B", []); | 8667 ClassElement elementB = ElementFactory.classElement2("B", []); |
| 8648 ClassElement elementC = ElementFactory.classElement2("C", []); | 8668 ClassElement elementC = ElementFactory.classElement2("C", []); |
| 8649 ClassElement elementD = ElementFactory.classElement2("D", []); | 8669 ClassElement elementD = ElementFactory.classElement2("D", []); |
| 8650 WithClause withClause = ASTFactory.withClause([ASTFactory.typeName(elementC,
[])]); | 8670 WithClause withClause = ASTFactory.withClause([ASTFactory.typeName(elementC,
[])]); |
| 8651 ImplementsClause implementsClause = ASTFactory.implementsClause([ASTFactory.
typeName(elementD, [])]); | 8671 ImplementsClause implementsClause = ASTFactory.implementsClause([ASTFactory.
typeName(elementD, [])]); |
| 8652 ClassTypeAlias alias = ASTFactory.classTypeAlias("A", null, null, ASTFactory
.typeName(elementB, []), withClause, implementsClause); | 8672 ClassTypeAlias alias = ASTFactory.classTypeAlias("A", null, null, ASTFactory
.typeName(elementB, []), withClause, implementsClause); |
| 8653 alias.name.staticElement = elementA; | 8673 alias.name.staticElement = elementA; |
| 8654 resolveNode(alias, [elementA, elementB, elementC, elementD]); | 8674 resolveNode(alias, [elementA, elementB, elementC, elementD]); |
| 8655 JUnitTestCase.assertSame(elementB.type, elementA.supertype); | 8675 JUnitTestCase.assertSame(elementB.type, elementA.supertype); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8691 InterfaceType intType = _typeProvider.intType; | 8711 InterfaceType intType = _typeProvider.intType; |
| 8692 TypeName intTypeName = ASTFactory.typeName4("int", []); | 8712 TypeName intTypeName = ASTFactory.typeName4("int", []); |
| 8693 String parameterName = "p"; | 8713 String parameterName = "p"; |
| 8694 FormalParameter node = ASTFactory.fieldFormalParameter(null, intTypeName, pa
rameterName); | 8714 FormalParameter node = ASTFactory.fieldFormalParameter(null, intTypeName, pa
rameterName); |
| 8695 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); | 8715 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); |
| 8696 JUnitTestCase.assertSame(intType, resolve6(node, [intType.element])); | 8716 JUnitTestCase.assertSame(intType, resolve6(node, [intType.element])); |
| 8697 _listener.assertNoErrors(); | 8717 _listener.assertNoErrors(); |
| 8698 } | 8718 } |
| 8699 | 8719 |
| 8700 void test_visitSimpleFormalParameter_noType() { | 8720 void test_visitSimpleFormalParameter_noType() { |
| 8721 // p |
| 8701 FormalParameter node = ASTFactory.simpleFormalParameter3("p"); | 8722 FormalParameter node = ASTFactory.simpleFormalParameter3("p"); |
| 8702 node.identifier.staticElement = new ParameterElementImpl.con1(ASTFactory.ide
ntifier3("p")); | 8723 node.identifier.staticElement = new ParameterElementImpl.con1(ASTFactory.ide
ntifier3("p")); |
| 8703 JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve6(node, [])); | 8724 JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve6(node, [])); |
| 8704 _listener.assertNoErrors(); | 8725 _listener.assertNoErrors(); |
| 8705 } | 8726 } |
| 8706 | 8727 |
| 8707 void test_visitSimpleFormalParameter_type() { | 8728 void test_visitSimpleFormalParameter_type() { |
| 8729 // int p |
| 8708 InterfaceType intType = _typeProvider.intType; | 8730 InterfaceType intType = _typeProvider.intType; |
| 8709 ClassElement intElement = intType.element; | 8731 ClassElement intElement = intType.element; |
| 8710 FormalParameter node = ASTFactory.simpleFormalParameter4(ASTFactory.typeName
(intElement, []), "p"); | 8732 FormalParameter node = ASTFactory.simpleFormalParameter4(ASTFactory.typeName
(intElement, []), "p"); |
| 8711 SimpleIdentifier identifier = node.identifier; | 8733 SimpleIdentifier identifier = node.identifier; |
| 8712 ParameterElementImpl element = new ParameterElementImpl.con1(identifier); | 8734 ParameterElementImpl element = new ParameterElementImpl.con1(identifier); |
| 8713 identifier.staticElement = element; | 8735 identifier.staticElement = element; |
| 8714 JUnitTestCase.assertSame(intType, resolve6(node, [intElement])); | 8736 JUnitTestCase.assertSame(intType, resolve6(node, [intElement])); |
| 8715 _listener.assertNoErrors(); | 8737 _listener.assertNoErrors(); |
| 8716 } | 8738 } |
| 8717 | 8739 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9068 } | 9090 } |
| 9069 | 9091 |
| 9070 static dartSuite() { | 9092 static dartSuite() { |
| 9071 _ut.group('ResolverTestCase', () { | 9093 _ut.group('ResolverTestCase', () { |
| 9072 }); | 9094 }); |
| 9073 } | 9095 } |
| 9074 } | 9096 } |
| 9075 | 9097 |
| 9076 class TypeProviderImplTest extends EngineTestCase { | 9098 class TypeProviderImplTest extends EngineTestCase { |
| 9077 void test_creation() { | 9099 void test_creation() { |
| 9100 // |
| 9101 // Create a mock library element with the types expected to be in dart:core.
We cannot use |
| 9102 // either ElementFactory or TestTypeProvider (which uses ElementFactory) bec
ause we side-effect |
| 9103 // the elements in ways that would break other tests. |
| 9104 // |
| 9078 InterfaceType objectType = classElement("Object", null, []).type; | 9105 InterfaceType objectType = classElement("Object", null, []).type; |
| 9079 InterfaceType boolType = classElement("bool", objectType, []).type; | 9106 InterfaceType boolType = classElement("bool", objectType, []).type; |
| 9080 InterfaceType numType = classElement("num", objectType, []).type; | 9107 InterfaceType numType = classElement("num", objectType, []).type; |
| 9081 InterfaceType doubleType = classElement("double", numType, []).type; | 9108 InterfaceType doubleType = classElement("double", numType, []).type; |
| 9082 InterfaceType functionType = classElement("Function", objectType, []).type; | 9109 InterfaceType functionType = classElement("Function", objectType, []).type; |
| 9083 InterfaceType intType = classElement("int", numType, []).type; | 9110 InterfaceType intType = classElement("int", numType, []).type; |
| 9084 InterfaceType listType = classElement("List", objectType, ["E"]).type; | 9111 InterfaceType listType = classElement("List", objectType, ["E"]).type; |
| 9085 InterfaceType mapType = classElement("Map", objectType, ["K", "V"]).type; | 9112 InterfaceType mapType = classElement("Map", objectType, ["K", "V"]).type; |
| 9086 InterfaceType stackTraceType = classElement("StackTrace", objectType, []).ty
pe; | 9113 InterfaceType stackTraceType = classElement("StackTrace", objectType, []).ty
pe; |
| 9087 InterfaceType stringType = classElement("String", objectType, []).type; | 9114 InterfaceType stringType = classElement("String", objectType, []).type; |
| 9088 InterfaceType symbolType = classElement("Symbol", objectType, []).type; | 9115 InterfaceType symbolType = classElement("Symbol", objectType, []).type; |
| 9089 InterfaceType typeType = classElement("Type", objectType, []).type; | 9116 InterfaceType typeType = classElement("Type", objectType, []).type; |
| 9090 CompilationUnitElementImpl unit = new CompilationUnitElementImpl("lib.dart")
; | 9117 CompilationUnitElementImpl unit = new CompilationUnitElementImpl("lib.dart")
; |
| 9091 unit.types = <ClassElement> [ | 9118 unit.types = <ClassElement> [ |
| 9092 boolType.element, | 9119 boolType.element, |
| 9093 doubleType.element, | 9120 doubleType.element, |
| 9094 functionType.element, | 9121 functionType.element, |
| 9095 intType.element, | 9122 intType.element, |
| 9096 listType.element, | 9123 listType.element, |
| 9097 mapType.element, | 9124 mapType.element, |
| 9098 objectType.element, | 9125 objectType.element, |
| 9099 stackTraceType.element, | 9126 stackTraceType.element, |
| 9100 stringType.element, | 9127 stringType.element, |
| 9101 symbolType.element, | 9128 symbolType.element, |
| 9102 typeType.element]; | 9129 typeType.element]; |
| 9103 LibraryElementImpl library = new LibraryElementImpl(new AnalysisContextImpl(
), ASTFactory.libraryIdentifier2(["lib"])); | 9130 LibraryElementImpl library = new LibraryElementImpl(new AnalysisContextImpl(
), ASTFactory.libraryIdentifier2(["lib"])); |
| 9104 library.definingCompilationUnit = unit; | 9131 library.definingCompilationUnit = unit; |
| 9132 // |
| 9133 // Create a type provider and ensure that it can return the expected types. |
| 9134 // |
| 9105 TypeProviderImpl provider = new TypeProviderImpl(library); | 9135 TypeProviderImpl provider = new TypeProviderImpl(library); |
| 9106 JUnitTestCase.assertSame(boolType, provider.boolType); | 9136 JUnitTestCase.assertSame(boolType, provider.boolType); |
| 9107 JUnitTestCase.assertNotNull(provider.bottomType); | 9137 JUnitTestCase.assertNotNull(provider.bottomType); |
| 9108 JUnitTestCase.assertSame(doubleType, provider.doubleType); | 9138 JUnitTestCase.assertSame(doubleType, provider.doubleType); |
| 9109 JUnitTestCase.assertNotNull(provider.dynamicType); | 9139 JUnitTestCase.assertNotNull(provider.dynamicType); |
| 9110 JUnitTestCase.assertSame(functionType, provider.functionType); | 9140 JUnitTestCase.assertSame(functionType, provider.functionType); |
| 9111 JUnitTestCase.assertSame(intType, provider.intType); | 9141 JUnitTestCase.assertSame(intType, provider.intType); |
| 9112 JUnitTestCase.assertSame(listType, provider.listType); | 9142 JUnitTestCase.assertSame(listType, provider.listType); |
| 9113 JUnitTestCase.assertSame(mapType, provider.mapType); | 9143 JUnitTestCase.assertSame(mapType, provider.mapType); |
| 9114 JUnitTestCase.assertSame(objectType, provider.objectType); | 9144 JUnitTestCase.assertSame(objectType, provider.objectType); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9899 "class A {", | 9929 "class A {", |
| 9900 " A() {}", | 9930 " A() {}", |
| 9901 "}", | 9931 "}", |
| 9902 "class B extends Object mixin A {}"])); | 9932 "class B extends Object mixin A {}"])); |
| 9903 resolve(source); | 9933 resolve(source); |
| 9904 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 9934 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 9905 verify([source]); | 9935 verify([source]); |
| 9906 } | 9936 } |
| 9907 | 9937 |
| 9908 void fail_mixinOfNonClass() { | 9938 void fail_mixinOfNonClass() { |
| 9939 // TODO(brianwilkerson) Compare with MIXIN_WITH_NON_CLASS_SUPERCLASS. |
| 9909 Source source = addSource(EngineTestCase.createSource(["var A;", "class B ex
tends Object mixin A {}"])); | 9940 Source source = addSource(EngineTestCase.createSource(["var A;", "class B ex
tends Object mixin A {}"])); |
| 9910 resolve(source); | 9941 resolve(source); |
| 9911 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); | 9942 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_NON_CLASS]); |
| 9912 verify([source]); | 9943 verify([source]); |
| 9913 } | 9944 } |
| 9914 | 9945 |
| 9915 void fail_objectCannotExtendAnotherClass() { | 9946 void fail_objectCannotExtendAnotherClass() { |
| 9916 Source source = addSource(EngineTestCase.createSource([])); | 9947 Source source = addSource(EngineTestCase.createSource([])); |
| 9917 resolve(source); | 9948 resolve(source); |
| 9918 assertErrors(source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLAS
S]); | 9949 assertErrors(source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLAS
S]); |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10920 "class A {", | 10951 "class A {", |
| 10921 " final int x;", | 10952 " final int x;", |
| 10922 " const A() : x = '';", | 10953 " const A() : x = '';", |
| 10923 "}"])); | 10954 "}"])); |
| 10924 resolve(source); | 10955 resolve(source); |
| 10925 assertErrors(source, [CompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIG
NABLE]); | 10956 assertErrors(source, [CompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIG
NABLE]); |
| 10926 verify([source]); | 10957 verify([source]); |
| 10927 } | 10958 } |
| 10928 | 10959 |
| 10929 void test_fieldInitializerOutsideConstructor() { | 10960 void test_fieldInitializerOutsideConstructor() { |
| 10961 // TODO(brianwilkerson) Fix the duplicate error messages. |
| 10930 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m(this.x) {}", "}"])); | 10962 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m(this.x) {}", "}"])); |
| 10931 resolve(source); | 10963 resolve(source); |
| 10932 assertErrors(source, [ | 10964 assertErrors(source, [ |
| 10933 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, | 10965 ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, |
| 10934 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); | 10966 CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); |
| 10935 verify([source]); | 10967 verify([source]); |
| 10936 } | 10968 } |
| 10937 | 10969 |
| 10938 void test_fieldInitializerOutsideConstructor_defaultParameter() { | 10970 void test_fieldInitializerOutsideConstructor_defaultParameter() { |
| 10939 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m([this.x]) {}", "}"])); | 10971 Source source = addSource(EngineTestCase.createSource(["class A {", " int x
;", " m([this.x]) {}", "}"])); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11191 " var f;", | 11223 " var f;", |
| 11192 "}"])); | 11224 "}"])); |
| 11193 resolve(source); | 11225 resolve(source); |
| 11194 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); | 11226 assertErrors(source, [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIA
LIZER]); |
| 11195 verify([source]); | 11227 verify([source]); |
| 11196 } | 11228 } |
| 11197 | 11229 |
| 11198 void test_importInternalLibrary() { | 11230 void test_importInternalLibrary() { |
| 11199 Source source = addSource(EngineTestCase.createSource(["import 'dart:_interc
eptors';"])); | 11231 Source source = addSource(EngineTestCase.createSource(["import 'dart:_interc
eptors';"])); |
| 11200 resolve(source); | 11232 resolve(source); |
| 11233 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w
e could prevent |
| 11234 // the hint from being generated by testing the import directive for the err
or, this is such a |
| 11235 // minor corner case that we don't think we should add the additional comput
ation time to figure |
| 11236 // out such cases. |
| 11201 assertErrors(source, [ | 11237 assertErrors(source, [ |
| 11202 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 11238 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 11203 HintCode.UNUSED_IMPORT]); | 11239 HintCode.UNUSED_IMPORT]); |
| 11204 verify([source]); | 11240 verify([source]); |
| 11205 } | 11241 } |
| 11206 | 11242 |
| 11207 void test_importInternalLibrary_collection() { | 11243 void test_importInternalLibrary_collection() { |
| 11208 Source source = addSource(EngineTestCase.createSource(["import 'dart:_collec
tion-dev';"])); | 11244 Source source = addSource(EngineTestCase.createSource(["import 'dart:_collec
tion-dev';"])); |
| 11209 resolve(source); | 11245 resolve(source); |
| 11246 // Note, in these error cases we may generate an UNUSED_IMPORT hint, while w
e could prevent |
| 11247 // the hint from being generated by testing the import directive for the err
or, this is such a |
| 11248 // minor corner case that we don't think we should add the additional comput
ation time to figure |
| 11249 // out such cases. |
| 11210 assertErrors(source, [ | 11250 assertErrors(source, [ |
| 11211 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, | 11251 CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, |
| 11212 HintCode.UNUSED_IMPORT]); | 11252 HintCode.UNUSED_IMPORT]); |
| 11213 verify([source]); | 11253 verify([source]); |
| 11214 } | 11254 } |
| 11215 | 11255 |
| 11216 void test_importOfNonLibrary() { | 11256 void test_importOfNonLibrary() { |
| 11217 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo
rt 'part.dart';", "A a;"])); | 11257 Source source = addSource(EngineTestCase.createSource(["library lib;", "impo
rt 'part.dart';", "A a;"])); |
| 11218 addSource2("/part.dart", EngineTestCase.createSource(["part of lib;", "class
A{}"])); | 11258 addSource2("/part.dart", EngineTestCase.createSource(["part of lib;", "class
A{}"])); |
| 11219 resolve(source); | 11259 resolve(source); |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11802 "class A {}", | 11842 "class A {}", |
| 11803 "class B extends A {", | 11843 "class B extends A {", |
| 11804 " B() : super(), super() {}", | 11844 " B() : super(), super() {}", |
| 11805 "}"])); | 11845 "}"])); |
| 11806 resolve(source); | 11846 resolve(source); |
| 11807 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); | 11847 assertErrors(source, [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]); |
| 11808 verify([source]); | 11848 verify([source]); |
| 11809 } | 11849 } |
| 11810 | 11850 |
| 11811 void test_nativeClauseInNonSDKCode() { | 11851 void test_nativeClauseInNonSDKCode() { |
| 11852 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 11853 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 11812 Source source = addSource(EngineTestCase.createSource(["class A native 'stri
ng' {}"])); | 11854 Source source = addSource(EngineTestCase.createSource(["class A native 'stri
ng' {}"])); |
| 11813 resolve(source); | 11855 resolve(source); |
| 11814 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); | 11856 assertErrors(source, [ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE]); |
| 11815 verify([source]); | 11857 verify([source]); |
| 11816 } | 11858 } |
| 11817 | 11859 |
| 11818 void test_nativeFunctionBodyInNonSDKCode_function() { | 11860 void test_nativeFunctionBodyInNonSDKCode_function() { |
| 11861 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 11862 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 11819 Source source = addSource(EngineTestCase.createSource(["int m(a) native 'str
ing';"])); | 11863 Source source = addSource(EngineTestCase.createSource(["int m(a) native 'str
ing';"])); |
| 11820 resolve(source); | 11864 resolve(source); |
| 11821 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; | 11865 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; |
| 11822 verify([source]); | 11866 verify([source]); |
| 11823 } | 11867 } |
| 11824 | 11868 |
| 11825 void test_nativeFunctionBodyInNonSDKCode_method() { | 11869 void test_nativeFunctionBodyInNonSDKCode_method() { |
| 11870 // TODO(jwren) Move this test somewhere else: This test verifies a parser er
ror code is generated |
| 11871 // through the ErrorVerifier, it is not a CompileTimeErrorCode. |
| 11826 Source source = addSource(EngineTestCase.createSource(["class A{", " static
int m(a) native 'string';", "}"])); | 11872 Source source = addSource(EngineTestCase.createSource(["class A{", " static
int m(a) native 'string';", "}"])); |
| 11827 resolve(source); | 11873 resolve(source); |
| 11828 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; | 11874 assertErrors(source, [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE])
; |
| 11829 verify([source]); | 11875 verify([source]); |
| 11830 } | 11876 } |
| 11831 | 11877 |
| 11832 void test_noAnnotationConstructorArguments() { | 11878 void test_noAnnotationConstructorArguments() { |
| 11833 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "@A", "main() {", "}"])); | 11879 Source source = addSource(EngineTestCase.createSource(["class A {", " const
A();", "}", "@A", "main() {", "}"])); |
| 11834 resolve(source); | 11880 resolve(source); |
| 11835 assertErrors(source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMEN
TS]); | 11881 assertErrors(source, [CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMEN
TS]); |
| (...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14431 return null; | 14477 return null; |
| 14432 } | 14478 } |
| 14433 | 14479 |
| 14434 Object visitImportDirective(ImportDirective node) => null; | 14480 Object visitImportDirective(ImportDirective node) => null; |
| 14435 | 14481 |
| 14436 Object visitLabel(Label node) => null; | 14482 Object visitLabel(Label node) => null; |
| 14437 | 14483 |
| 14438 Object visitLibraryIdentifier(LibraryIdentifier node) => null; | 14484 Object visitLibraryIdentifier(LibraryIdentifier node) => null; |
| 14439 | 14485 |
| 14440 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 14486 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 14487 // In cases where we have a prefixed identifier where the prefix is dynamic,
we don't want to |
| 14488 // assert that the node will have a type. |
| 14441 if (node.staticType == null && identical(node.prefix.staticType, DynamicType
Impl.instance)) { | 14489 if (node.staticType == null && identical(node.prefix.staticType, DynamicType
Impl.instance)) { |
| 14442 return null; | 14490 return null; |
| 14443 } | 14491 } |
| 14444 return super.visitPrefixedIdentifier(node); | 14492 return super.visitPrefixedIdentifier(node); |
| 14445 } | 14493 } |
| 14446 | 14494 |
| 14447 Object visitSimpleIdentifier(SimpleIdentifier node) { | 14495 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 14496 // In cases where identifiers are being used for something other than an exp
ressions, |
| 14497 // then they can be ignored. |
| 14448 ASTNode parent = node.parent; | 14498 ASTNode parent = node.parent; |
| 14449 if (parent is MethodInvocation && identical(node, parent.methodName)) { | 14499 if (parent is MethodInvocation && identical(node, parent.methodName)) { |
| 14450 return null; | 14500 return null; |
| 14451 } else if (parent is RedirectingConstructorInvocation && identical(node, par
ent.constructorName)) { | 14501 } else if (parent is RedirectingConstructorInvocation && identical(node, par
ent.constructorName)) { |
| 14452 return null; | 14502 return null; |
| 14453 } else if (parent is SuperConstructorInvocation && identical(node, parent.co
nstructorName)) { | 14503 } else if (parent is SuperConstructorInvocation && identical(node, parent.co
nstructorName)) { |
| 14454 return null; | 14504 return null; |
| 14455 } else if (parent is ConstructorName && identical(node, parent.name)) { | 14505 } else if (parent is ConstructorName && identical(node, parent.name)) { |
| 14456 return null; | 14506 return null; |
| 14457 } else if (parent is ConstructorFieldInitializer && identical(node, parent.f
ieldName)) { | 14507 } else if (parent is ConstructorFieldInitializer && identical(node, parent.f
ieldName)) { |
| 14458 return null; | 14508 return null; |
| 14459 } else if (node.staticElement is PrefixElement) { | 14509 } else if (node.staticElement is PrefixElement) { |
| 14510 // Prefixes don't have a type. |
| 14460 return null; | 14511 return null; |
| 14461 } | 14512 } |
| 14462 return super.visitSimpleIdentifier(node); | 14513 return super.visitSimpleIdentifier(node); |
| 14463 } | 14514 } |
| 14464 | 14515 |
| 14465 Object visitTypeName(TypeName node) { | 14516 Object visitTypeName(TypeName node) { |
| 14517 // Note: do not visit children from this node, the child SimpleIdentifier in
TypeName |
| 14518 // (i.e. "String") does not have a static type defined. |
| 14466 if (node.type == null) { | 14519 if (node.type == null) { |
| 14467 _unresolvedTypes.add(node); | 14520 _unresolvedTypes.add(node); |
| 14468 } else { | 14521 } else { |
| 14469 _resolvedTypeCount++; | 14522 _resolvedTypeCount++; |
| 14470 } | 14523 } |
| 14471 return null; | 14524 return null; |
| 14472 } | 14525 } |
| 14473 | 14526 |
| 14474 String getFileName(ASTNode node) { | 14527 String getFileName(ASTNode node) { |
| 14528 // TODO (jwren) there are two copies of this method, one here and one in Res
olutionVerifier, |
| 14529 // they should be resolved into a single method |
| 14475 if (node != null) { | 14530 if (node != null) { |
| 14476 ASTNode root = node.root; | 14531 ASTNode root = node.root; |
| 14477 if (root is CompilationUnit) { | 14532 if (root is CompilationUnit) { |
| 14478 CompilationUnit rootCU = root; | 14533 CompilationUnit rootCU = root; |
| 14479 if (rootCU.element != null) { | 14534 if (rootCU.element != null) { |
| 14480 return rootCU.element.source.fullName; | 14535 return rootCU.element.source.fullName; |
| 14481 } else { | 14536 } else { |
| 14482 return "<unknown file- CompilationUnit.getElement() returned null>"; | 14537 return "<unknown file- CompilationUnit.getElement() returned null>"; |
| 14483 } | 14538 } |
| 14484 } else { | 14539 } else { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14714 */ | 14769 */ |
| 14715 ResolverVisitor _visitor; | 14770 ResolverVisitor _visitor; |
| 14716 | 14771 |
| 14717 /** | 14772 /** |
| 14718 * The resolver being used to resolve the test cases. | 14773 * The resolver being used to resolve the test cases. |
| 14719 */ | 14774 */ |
| 14720 ElementResolver _resolver; | 14775 ElementResolver _resolver; |
| 14721 | 14776 |
| 14722 void fail_visitExportDirective_combinators() { | 14777 void fail_visitExportDirective_combinators() { |
| 14723 JUnitTestCase.fail("Not yet tested"); | 14778 JUnitTestCase.fail("Not yet tested"); |
| 14779 // Need to set up the exported library so that the identifier can be resolve
d |
| 14724 ExportDirective directive = ASTFactory.exportDirective2(null, [ASTFactory.hi
deCombinator2(["A"])]); | 14780 ExportDirective directive = ASTFactory.exportDirective2(null, [ASTFactory.hi
deCombinator2(["A"])]); |
| 14725 resolveNode(directive, []); | 14781 resolveNode(directive, []); |
| 14726 _listener.assertNoErrors(); | 14782 _listener.assertNoErrors(); |
| 14727 } | 14783 } |
| 14728 | 14784 |
| 14729 void fail_visitFunctionExpressionInvocation() { | 14785 void fail_visitFunctionExpressionInvocation() { |
| 14730 JUnitTestCase.fail("Not yet tested"); | 14786 JUnitTestCase.fail("Not yet tested"); |
| 14731 _listener.assertNoErrors(); | 14787 _listener.assertNoErrors(); |
| 14732 } | 14788 } |
| 14733 | 14789 |
| 14734 void fail_visitImportDirective_combinators_noPrefix() { | 14790 void fail_visitImportDirective_combinators_noPrefix() { |
| 14735 JUnitTestCase.fail("Not yet tested"); | 14791 JUnitTestCase.fail("Not yet tested"); |
| 14792 // Need to set up the imported library so that the identifier can be resolve
d |
| 14736 ImportDirective directive = ASTFactory.importDirective2(null, null, [ASTFact
ory.showCombinator2(["A"])]); | 14793 ImportDirective directive = ASTFactory.importDirective2(null, null, [ASTFact
ory.showCombinator2(["A"])]); |
| 14737 resolveNode(directive, []); | 14794 resolveNode(directive, []); |
| 14738 _listener.assertNoErrors(); | 14795 _listener.assertNoErrors(); |
| 14739 } | 14796 } |
| 14740 | 14797 |
| 14741 void fail_visitImportDirective_combinators_prefix() { | 14798 void fail_visitImportDirective_combinators_prefix() { |
| 14742 JUnitTestCase.fail("Not yet tested"); | 14799 JUnitTestCase.fail("Not yet tested"); |
| 14800 // Need to set up the imported library so that the identifiers can be resolv
ed |
| 14743 String prefixName = "p"; | 14801 String prefixName = "p"; |
| 14744 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E
lementFactory.prefix(prefixName), [])]; | 14802 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E
lementFactory.prefix(prefixName), [])]; |
| 14745 ImportDirective directive = ASTFactory.importDirective2(null, prefixName, [ | 14803 ImportDirective directive = ASTFactory.importDirective2(null, prefixName, [ |
| 14746 ASTFactory.showCombinator2(["A"]), | 14804 ASTFactory.showCombinator2(["A"]), |
| 14747 ASTFactory.hideCombinator2(["B"])]); | 14805 ASTFactory.hideCombinator2(["B"])]); |
| 14748 resolveNode(directive, []); | 14806 resolveNode(directive, []); |
| 14749 _listener.assertNoErrors(); | 14807 _listener.assertNoErrors(); |
| 14750 } | 14808 } |
| 14751 | 14809 |
| 14752 void fail_visitRedirectingConstructorInvocation() { | 14810 void fail_visitRedirectingConstructorInvocation() { |
| 14753 JUnitTestCase.fail("Not yet tested"); | 14811 JUnitTestCase.fail("Not yet tested"); |
| 14754 _listener.assertNoErrors(); | 14812 _listener.assertNoErrors(); |
| 14755 } | 14813 } |
| 14756 | 14814 |
| 14757 void setUp() { | 14815 void setUp() { |
| 14758 _listener = new GatheringErrorListener(); | 14816 _listener = new GatheringErrorListener(); |
| 14759 _typeProvider = new TestTypeProvider(); | 14817 _typeProvider = new TestTypeProvider(); |
| 14760 _resolver = createResolver(); | 14818 _resolver = createResolver(); |
| 14761 } | 14819 } |
| 14762 | 14820 |
| 14763 void test_lookUpMethodInInterfaces() { | 14821 void test_lookUpMethodInInterfaces() { |
| 14764 InterfaceType intType = _typeProvider.intType; | 14822 InterfaceType intType = _typeProvider.intType; |
| 14823 // |
| 14824 // abstract class A { int operator[](int index); } |
| 14825 // |
| 14765 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 14826 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 14766 MethodElement operator = ElementFactory.methodElement("[]", intType, [intTyp
e]); | 14827 MethodElement operator = ElementFactory.methodElement("[]", intType, [intTyp
e]); |
| 14767 classA.methods = <MethodElement> [operator]; | 14828 classA.methods = <MethodElement> [operator]; |
| 14829 // |
| 14830 // class B implements A {} |
| 14831 // |
| 14768 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 14832 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 14769 classB.interfaces = <InterfaceType> [classA.type]; | 14833 classB.interfaces = <InterfaceType> [classA.type]; |
| 14834 // |
| 14835 // class C extends Object with B {} |
| 14836 // |
| 14770 ClassElementImpl classC = ElementFactory.classElement2("C", []); | 14837 ClassElementImpl classC = ElementFactory.classElement2("C", []); |
| 14771 classC.mixins = <InterfaceType> [classB.type]; | 14838 classC.mixins = <InterfaceType> [classB.type]; |
| 14839 // |
| 14840 // class D extends C {} |
| 14841 // |
| 14772 ClassElementImpl classD = ElementFactory.classElement("D", classC.type, []); | 14842 ClassElementImpl classD = ElementFactory.classElement("D", classC.type, []); |
| 14843 // |
| 14844 // D a; |
| 14845 // a[i]; |
| 14846 // |
| 14773 SimpleIdentifier array = ASTFactory.identifier3("a"); | 14847 SimpleIdentifier array = ASTFactory.identifier3("a"); |
| 14774 array.staticType = classD.type; | 14848 array.staticType = classD.type; |
| 14775 IndexExpression expression = ASTFactory.indexExpression(array, ASTFactory.id
entifier3("i")); | 14849 IndexExpression expression = ASTFactory.indexExpression(array, ASTFactory.id
entifier3("i")); |
| 14776 JUnitTestCase.assertSame(operator, resolve5(expression, [])); | 14850 JUnitTestCase.assertSame(operator, resolve5(expression, [])); |
| 14777 _listener.assertNoErrors(); | 14851 _listener.assertNoErrors(); |
| 14778 } | 14852 } |
| 14779 | 14853 |
| 14780 void test_visitAssignmentExpression_compound() { | 14854 void test_visitAssignmentExpression_compound() { |
| 14781 InterfaceType intType = _typeProvider.intType; | 14855 InterfaceType intType = _typeProvider.intType; |
| 14782 SimpleIdentifier leftHandSide = ASTFactory.identifier3("a"); | 14856 SimpleIdentifier leftHandSide = ASTFactory.identifier3("a"); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15021 target.staticType = classA.type; | 15095 target.staticType = classA.type; |
| 15022 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(getterName)); | 15096 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(getterName)); |
| 15023 resolveNode(identifier, []); | 15097 resolveNode(identifier, []); |
| 15024 JUnitTestCase.assertSame(getter, identifier.staticElement); | 15098 JUnitTestCase.assertSame(getter, identifier.staticElement); |
| 15025 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); | 15099 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); |
| 15026 _listener.assertNoErrors(); | 15100 _listener.assertNoErrors(); |
| 15027 } | 15101 } |
| 15028 | 15102 |
| 15029 void test_visitPrefixedIdentifier_staticClassMember_getter() { | 15103 void test_visitPrefixedIdentifier_staticClassMember_getter() { |
| 15030 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 15104 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 15105 // set accessors |
| 15031 String propName = "b"; | 15106 String propName = "b"; |
| 15032 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); | 15107 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); |
| 15033 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 15108 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 15034 classA.accessors = <PropertyAccessorElement> [getter, setter]; | 15109 classA.accessors = <PropertyAccessorElement> [getter, setter]; |
| 15110 // prepare "A.m" |
| 15035 SimpleIdentifier target = ASTFactory.identifier3("A"); | 15111 SimpleIdentifier target = ASTFactory.identifier3("A"); |
| 15036 target.staticElement = classA; | 15112 target.staticElement = classA; |
| 15037 target.staticType = classA.type; | 15113 target.staticType = classA.type; |
| 15038 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); | 15114 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); |
| 15115 // resolve |
| 15039 resolveNode(identifier, []); | 15116 resolveNode(identifier, []); |
| 15040 JUnitTestCase.assertSame(getter, identifier.staticElement); | 15117 JUnitTestCase.assertSame(getter, identifier.staticElement); |
| 15041 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); | 15118 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); |
| 15042 _listener.assertNoErrors(); | 15119 _listener.assertNoErrors(); |
| 15043 } | 15120 } |
| 15044 | 15121 |
| 15045 void test_visitPrefixedIdentifier_staticClassMember_method() { | 15122 void test_visitPrefixedIdentifier_staticClassMember_method() { |
| 15046 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 15123 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 15124 // set accessors |
| 15047 String propName = "m"; | 15125 String propName = "m"; |
| 15048 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 15126 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 15049 classA.accessors = <PropertyAccessorElement> [setter]; | 15127 classA.accessors = <PropertyAccessorElement> [setter]; |
| 15128 // set methods |
| 15050 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy
pe, []); | 15129 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy
pe, []); |
| 15051 classA.methods = <MethodElement> [method]; | 15130 classA.methods = <MethodElement> [method]; |
| 15131 // prepare "A.m" |
| 15052 SimpleIdentifier target = ASTFactory.identifier3("A"); | 15132 SimpleIdentifier target = ASTFactory.identifier3("A"); |
| 15053 target.staticElement = classA; | 15133 target.staticElement = classA; |
| 15054 target.staticType = classA.type; | 15134 target.staticType = classA.type; |
| 15055 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); | 15135 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); |
| 15056 ASTFactory.assignmentExpression(identifier, TokenType.EQ, ASTFactory.nullLit
eral()); | 15136 ASTFactory.assignmentExpression(identifier, TokenType.EQ, ASTFactory.nullLit
eral()); |
| 15137 // resolve |
| 15057 resolveNode(identifier, []); | 15138 resolveNode(identifier, []); |
| 15058 JUnitTestCase.assertSame(method, identifier.staticElement); | 15139 JUnitTestCase.assertSame(method, identifier.staticElement); |
| 15059 JUnitTestCase.assertSame(method, identifier.identifier.staticElement); | 15140 JUnitTestCase.assertSame(method, identifier.identifier.staticElement); |
| 15060 _listener.assertNoErrors(); | 15141 _listener.assertNoErrors(); |
| 15061 } | 15142 } |
| 15062 | 15143 |
| 15063 void test_visitPrefixedIdentifier_staticClassMember_setter() { | 15144 void test_visitPrefixedIdentifier_staticClassMember_setter() { |
| 15064 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 15145 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 15146 // set accessors |
| 15065 String propName = "b"; | 15147 String propName = "b"; |
| 15066 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); | 15148 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); |
| 15067 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 15149 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 15068 classA.accessors = <PropertyAccessorElement> [getter, setter]; | 15150 classA.accessors = <PropertyAccessorElement> [getter, setter]; |
| 15151 // prepare "A.b = null" |
| 15069 SimpleIdentifier target = ASTFactory.identifier3("A"); | 15152 SimpleIdentifier target = ASTFactory.identifier3("A"); |
| 15070 target.staticElement = classA; | 15153 target.staticElement = classA; |
| 15071 target.staticType = classA.type; | 15154 target.staticType = classA.type; |
| 15072 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); | 15155 PrefixedIdentifier identifier = ASTFactory.identifier(target, ASTFactory.ide
ntifier3(propName)); |
| 15073 ASTFactory.assignmentExpression(identifier, TokenType.EQ, ASTFactory.nullLit
eral()); | 15156 ASTFactory.assignmentExpression(identifier, TokenType.EQ, ASTFactory.nullLit
eral()); |
| 15157 // resolve |
| 15074 resolveNode(identifier, []); | 15158 resolveNode(identifier, []); |
| 15075 JUnitTestCase.assertSame(setter, identifier.staticElement); | 15159 JUnitTestCase.assertSame(setter, identifier.staticElement); |
| 15076 JUnitTestCase.assertSame(setter, identifier.identifier.staticElement); | 15160 JUnitTestCase.assertSame(setter, identifier.identifier.staticElement); |
| 15077 _listener.assertNoErrors(); | 15161 _listener.assertNoErrors(); |
| 15078 } | 15162 } |
| 15079 | 15163 |
| 15080 void test_visitPrefixExpression() { | 15164 void test_visitPrefixExpression() { |
| 15081 InterfaceType numType = _typeProvider.numType; | 15165 InterfaceType numType = _typeProvider.numType; |
| 15082 SimpleIdentifier operand = ASTFactory.identifier3("i"); | 15166 SimpleIdentifier operand = ASTFactory.identifier3("i"); |
| 15083 operand.staticType = numType; | 15167 operand.staticType = numType; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 15094 classA.accessors = <PropertyAccessorElement> [getter]; | 15178 classA.accessors = <PropertyAccessorElement> [getter]; |
| 15095 SimpleIdentifier target = ASTFactory.identifier3("a"); | 15179 SimpleIdentifier target = ASTFactory.identifier3("a"); |
| 15096 target.staticType = classA.type; | 15180 target.staticType = classA.type; |
| 15097 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName); | 15181 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName); |
| 15098 resolveNode(access, []); | 15182 resolveNode(access, []); |
| 15099 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); | 15183 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); |
| 15100 _listener.assertNoErrors(); | 15184 _listener.assertNoErrors(); |
| 15101 } | 15185 } |
| 15102 | 15186 |
| 15103 void test_visitPropertyAccess_getter_super() { | 15187 void test_visitPropertyAccess_getter_super() { |
| 15188 // |
| 15189 // class A { |
| 15190 // int get b; |
| 15191 // } |
| 15192 // class B { |
| 15193 // ... super.m ... |
| 15194 // } |
| 15195 // |
| 15104 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 15196 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 15105 String getterName = "b"; | 15197 String getterName = "b"; |
| 15106 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); | 15198 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); |
| 15107 classA.accessors = <PropertyAccessorElement> [getter]; | 15199 classA.accessors = <PropertyAccessorElement> [getter]; |
| 15108 SuperExpression target = ASTFactory.superExpression(); | 15200 SuperExpression target = ASTFactory.superExpression(); |
| 15109 target.staticType = ElementFactory.classElement("B", classA.type, []).type; | 15201 target.staticType = ElementFactory.classElement("B", classA.type, []).type; |
| 15110 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName); | 15202 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName); |
| 15111 ASTFactory.methodDeclaration2(null, null, null, null, ASTFactory.identifier3
("m"), ASTFactory.formalParameterList([]), ASTFactory.expressionFunctionBody(acc
ess)); | 15203 ASTFactory.methodDeclaration2(null, null, null, null, ASTFactory.identifier3
("m"), ASTFactory.formalParameterList([]), ASTFactory.expressionFunctionBody(acc
ess)); |
| 15112 resolveNode(access, []); | 15204 resolveNode(access, []); |
| 15113 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); | 15205 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); |
| (...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17331 "abstract class B extends A {", | 17423 "abstract class B extends A {", |
| 17332 " m(p);", | 17424 " m(p);", |
| 17333 "}", | 17425 "}", |
| 17334 "class C extends B {}"])); | 17426 "class C extends B {}"])); |
| 17335 resolve(source); | 17427 resolve(source); |
| 17336 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); | 17428 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); |
| 17337 verify([source]); | 17429 verify([source]); |
| 17338 } | 17430 } |
| 17339 | 17431 |
| 17340 void test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubty
peIsUsedInImplementation() { | 17432 void test_nonAbstractClassInheritsAbstractMemberOne_ensureCorrectFunctionSubty
peIsUsedInImplementation() { |
| 17433 // bug 15028 |
| 17341 Source source = addSource(EngineTestCase.createSource([ | 17434 Source source = addSource(EngineTestCase.createSource([ |
| 17342 "class C {", | 17435 "class C {", |
| 17343 " foo(int x) => x;", | 17436 " foo(int x) => x;", |
| 17344 "}", | 17437 "}", |
| 17345 "abstract class D {", | 17438 "abstract class D {", |
| 17346 " foo(x, [y]);", | 17439 " foo(x, [y]);", |
| 17347 "}", | 17440 "}", |
| 17348 "class E extends C implements D {}"])); | 17441 "class E extends C implements D {}"])); |
| 17349 resolve(source); | 17442 resolve(source); |
| 17350 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); | 17443 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17393 " m(p);", | 17486 " m(p);", |
| 17394 "}", | 17487 "}", |
| 17395 "class C extends A {", | 17488 "class C extends A {", |
| 17396 "}"])); | 17489 "}"])); |
| 17397 resolve(source); | 17490 resolve(source); |
| 17398 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); | 17491 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); |
| 17399 verify([source]); | 17492 verify([source]); |
| 17400 } | 17493 } |
| 17401 | 17494 |
| 17402 void test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount(
) { | 17495 void test_nonAbstractClassInheritsAbstractMemberOne_method_optionalParamCount(
) { |
| 17496 // 7640 |
| 17403 Source source = addSource(EngineTestCase.createSource([ | 17497 Source source = addSource(EngineTestCase.createSource([ |
| 17404 "abstract class A {", | 17498 "abstract class A {", |
| 17405 " int x(int a);", | 17499 " int x(int a);", |
| 17406 "}", | 17500 "}", |
| 17407 "abstract class B {", | 17501 "abstract class B {", |
| 17408 " int x(int a, [int b]);", | 17502 " int x(int a, [int b]);", |
| 17409 "}", | 17503 "}", |
| 17410 "class C implements A, B {", | 17504 "class C implements A, B {", |
| 17411 "}"])); | 17505 "}"])); |
| 17412 resolve(source); | 17506 resolve(source); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 17432 " set s(int i);", | 17526 " set s(int i);", |
| 17433 "}", | 17527 "}", |
| 17434 "class C extends A {", | 17528 "class C extends A {", |
| 17435 "}"])); | 17529 "}"])); |
| 17436 resolve(source); | 17530 resolve(source); |
| 17437 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); | 17531 assertErrors(source, [StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT
_MEMBER_ONE]); |
| 17438 verify([source]); | 17532 verify([source]); |
| 17439 } | 17533 } |
| 17440 | 17534 |
| 17441 void test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() { | 17535 void test_nonAbstractClassInheritsAbstractMemberOne_superclasses_interface() { |
| 17536 // bug 11154 |
| 17442 Source source = addSource(EngineTestCase.createSource([ | 17537 Source source = addSource(EngineTestCase.createSource([ |
| 17443 "class A {", | 17538 "class A {", |
| 17444 " get a => 'a';", | 17539 " get a => 'a';", |
| 17445 "}", | 17540 "}", |
| 17446 "abstract class B implements A {", | 17541 "abstract class B implements A {", |
| 17447 " get b => 'b';", | 17542 " get b => 'b';", |
| 17448 "}", | 17543 "}", |
| 17449 "class C extends B {", | 17544 "class C extends B {", |
| 17450 "}"])); | 17545 "}"])); |
| 17451 resolve(source); | 17546 resolve(source); |
| (...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18721 * Creates new [AnalysisContext] using [AnalysisContextFactory#contextWithCore
]. | 18816 * Creates new [AnalysisContext] using [AnalysisContextFactory#contextWithCore
]. |
| 18722 */ | 18817 */ |
| 18723 AnalysisContextHelper() { | 18818 AnalysisContextHelper() { |
| 18724 context = AnalysisContextFactory.contextWithCore(); | 18819 context = AnalysisContextFactory.contextWithCore(); |
| 18725 _sourceFactory = context.sourceFactory; | 18820 _sourceFactory = context.sourceFactory; |
| 18726 _cache = _sourceFactory.contentCache; | 18821 _cache = _sourceFactory.contentCache; |
| 18727 } | 18822 } |
| 18728 | 18823 |
| 18729 Source addSource(String path, String code) { | 18824 Source addSource(String path, String code) { |
| 18730 Source source = new FileBasedSource.con1(_cache, FileUtilities2.createFile(p
ath)); | 18825 Source source = new FileBasedSource.con1(_cache, FileUtilities2.createFile(p
ath)); |
| 18826 // add source |
| 18731 { | 18827 { |
| 18732 _sourceFactory.setContents(source, ""); | 18828 _sourceFactory.setContents(source, ""); |
| 18733 ChangeSet changeSet = new ChangeSet(); | 18829 ChangeSet changeSet = new ChangeSet(); |
| 18734 changeSet.added(source); | 18830 changeSet.added(source); |
| 18735 context.applyChanges(changeSet); | 18831 context.applyChanges(changeSet); |
| 18736 } | 18832 } |
| 18833 // update source |
| 18737 context.setContents(source, code); | 18834 context.setContents(source, code); |
| 18738 return source; | 18835 return source; |
| 18739 } | 18836 } |
| 18740 | 18837 |
| 18741 CompilationUnit resolveDefiningUnit(Source source) { | 18838 CompilationUnit resolveDefiningUnit(Source source) { |
| 18742 LibraryElement libraryElement = context.computeLibraryElement(source); | 18839 LibraryElement libraryElement = context.computeLibraryElement(source); |
| 18743 return context.resolveCompilationUnit(source, libraryElement); | 18840 return context.resolveCompilationUnit(source, libraryElement); |
| 18744 } | 18841 } |
| 18745 } | 18842 } |
| 18746 | 18843 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19054 _typeType = ElementFactory.classElement2("Type", []).type; | 19151 _typeType = ElementFactory.classElement2("Type", []).type; |
| 19055 } | 19152 } |
| 19056 return _typeType; | 19153 return _typeType; |
| 19057 } | 19154 } |
| 19058 | 19155 |
| 19059 /** | 19156 /** |
| 19060 * Initialize the numeric types. They are created as a group so that we can (a
) create the right | 19157 * Initialize the numeric types. They are created as a group so that we can (a
) create the right |
| 19061 * hierarchy and (b) add members to them. | 19158 * hierarchy and (b) add members to them. |
| 19062 */ | 19159 */ |
| 19063 void initializeNumericTypes() { | 19160 void initializeNumericTypes() { |
| 19161 // |
| 19162 // Create the type hierarchy. |
| 19163 // |
| 19064 ClassElementImpl numElement = ElementFactory.classElement2("num", []); | 19164 ClassElementImpl numElement = ElementFactory.classElement2("num", []); |
| 19065 _numType = numElement.type; | 19165 _numType = numElement.type; |
| 19066 ClassElementImpl intElement = ElementFactory.classElement("int", _numType, [
]); | 19166 ClassElementImpl intElement = ElementFactory.classElement("int", _numType, [
]); |
| 19067 _intType = intElement.type; | 19167 _intType = intElement.type; |
| 19068 ClassElementImpl doubleElement = ElementFactory.classElement("double", _numT
ype, []); | 19168 ClassElementImpl doubleElement = ElementFactory.classElement("double", _numT
ype, []); |
| 19069 _doubleType = doubleElement.type; | 19169 _doubleType = doubleElement.type; |
| 19170 // |
| 19171 // Force the referenced types to be cached. |
| 19172 // |
| 19070 boolType; | 19173 boolType; |
| 19071 stringType; | 19174 stringType; |
| 19175 // |
| 19176 // Add the methods. |
| 19177 // |
| 19072 numElement.methods = <MethodElement> [ | 19178 numElement.methods = <MethodElement> [ |
| 19073 ElementFactory.methodElement("+", _numType, [_numType]), | 19179 ElementFactory.methodElement("+", _numType, [_numType]), |
| 19074 ElementFactory.methodElement("-", _numType, [_numType]), | 19180 ElementFactory.methodElement("-", _numType, [_numType]), |
| 19075 ElementFactory.methodElement("*", _numType, [_numType]), | 19181 ElementFactory.methodElement("*", _numType, [_numType]), |
| 19076 ElementFactory.methodElement("%", _numType, [_numType]), | 19182 ElementFactory.methodElement("%", _numType, [_numType]), |
| 19077 ElementFactory.methodElement("/", _doubleType, [_numType]), | 19183 ElementFactory.methodElement("/", _doubleType, [_numType]), |
| 19078 ElementFactory.methodElement("~/", _numType, [_numType]), | 19184 ElementFactory.methodElement("~/", _numType, [_numType]), |
| 19079 ElementFactory.methodElement("-", _numType, []), | 19185 ElementFactory.methodElement("-", _numType, []), |
| 19080 ElementFactory.methodElement("remainder", _numType, [_numType]), | 19186 ElementFactory.methodElement("remainder", _numType, [_numType]), |
| 19081 ElementFactory.methodElement("<", _boolType, [_numType]), | 19187 ElementFactory.methodElement("<", _boolType, [_numType]), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19177 | 19283 |
| 19178 /** | 19284 /** |
| 19179 * Initialize the given analysis context with a fake core library already reso
lved. | 19285 * Initialize the given analysis context with a fake core library already reso
lved. |
| 19180 * | 19286 * |
| 19181 * @param context the context to be initialized (not `null`) | 19287 * @param context the context to be initialized (not `null`) |
| 19182 * @return the analysis context that was created | 19288 * @return the analysis context that was created |
| 19183 */ | 19289 */ |
| 19184 static AnalysisContextImpl initContextWithCore(AnalysisContextImpl context) { | 19290 static AnalysisContextImpl initContextWithCore(AnalysisContextImpl context) { |
| 19185 AnalysisContext sdkContext = DirectoryBasedDartSdk.defaultSdk.context; | 19291 AnalysisContext sdkContext = DirectoryBasedDartSdk.defaultSdk.context; |
| 19186 SourceFactory sourceFactory = sdkContext.sourceFactory; | 19292 SourceFactory sourceFactory = sdkContext.sourceFactory; |
| 19293 // |
| 19294 // dart:core |
| 19295 // |
| 19187 TestTypeProvider provider = new TestTypeProvider(); | 19296 TestTypeProvider provider = new TestTypeProvider(); |
| 19188 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d
art"); | 19297 CompilationUnitElementImpl coreUnit = new CompilationUnitElementImpl("core.d
art"); |
| 19189 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); | 19298 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); |
| 19190 sdkContext.setContents(coreSource, ""); | 19299 sdkContext.setContents(coreSource, ""); |
| 19191 coreUnit.source = coreSource; | 19300 coreUnit.source = coreSource; |
| 19192 coreUnit.types = <ClassElement> [ | 19301 coreUnit.types = <ClassElement> [ |
| 19193 provider.boolType.element, | 19302 provider.boolType.element, |
| 19194 provider.deprecatedType.element, | 19303 provider.deprecatedType.element, |
| 19195 provider.doubleType.element, | 19304 provider.doubleType.element, |
| 19196 provider.functionType.element, | 19305 provider.functionType.element, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 19208 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory.topLevelVa
riableElement3("proxy", true, false, ElementFactory.classElement2("_Proxy", []).
type); | 19317 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory.topLevelVa
riableElement3("proxy", true, false, ElementFactory.classElement2("_Proxy", []).
type); |
| 19209 TopLevelVariableElement deprecatedTopLevelVariableElt = ElementFactory.topLe
velVariableElement3("deprecated", true, false, provider.deprecatedType); | 19318 TopLevelVariableElement deprecatedTopLevelVariableElt = ElementFactory.topLe
velVariableElement3("deprecated", true, false, provider.deprecatedType); |
| 19210 coreUnit.accessors = <PropertyAccessorElement> [ | 19319 coreUnit.accessors = <PropertyAccessorElement> [ |
| 19211 proxyTopLevelVariableElt.getter, | 19320 proxyTopLevelVariableElt.getter, |
| 19212 proxyTopLevelVariableElt.setter, | 19321 proxyTopLevelVariableElt.setter, |
| 19213 deprecatedTopLevelVariableElt.getter, | 19322 deprecatedTopLevelVariableElt.getter, |
| 19214 deprecatedTopLevelVariableElt.setter]; | 19323 deprecatedTopLevelVariableElt.setter]; |
| 19215 coreUnit.topLevelVariables = <TopLevelVariableElement> [proxyTopLevelVariabl
eElt, deprecatedTopLevelVariableElt]; | 19324 coreUnit.topLevelVariables = <TopLevelVariableElement> [proxyTopLevelVariabl
eElt, deprecatedTopLevelVariableElt]; |
| 19216 LibraryElementImpl coreLibrary = new LibraryElementImpl(sdkContext, ASTFacto
ry.libraryIdentifier2(["dart", "core"])); | 19325 LibraryElementImpl coreLibrary = new LibraryElementImpl(sdkContext, ASTFacto
ry.libraryIdentifier2(["dart", "core"])); |
| 19217 coreLibrary.definingCompilationUnit = coreUnit; | 19326 coreLibrary.definingCompilationUnit = coreUnit; |
| 19327 // |
| 19328 // dart:html |
| 19329 // |
| 19218 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d
artium.dart"); | 19330 CompilationUnitElementImpl htmlUnit = new CompilationUnitElementImpl("html_d
artium.dart"); |
| 19219 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); | 19331 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); |
| 19220 sdkContext.setContents(htmlSource, ""); | 19332 sdkContext.setContents(htmlSource, ""); |
| 19221 htmlUnit.source = htmlSource; | 19333 htmlUnit.source = htmlSource; |
| 19222 ClassElementImpl elementElement = ElementFactory.classElement2("Element", []
); | 19334 ClassElementImpl elementElement = ElementFactory.classElement2("Element", []
); |
| 19223 InterfaceType elementType = elementElement.type; | 19335 InterfaceType elementType = elementElement.type; |
| 19224 ClassElementImpl documentElement = ElementFactory.classElement("Document", e
lementType, []); | 19336 ClassElementImpl documentElement = ElementFactory.classElement("Document", e
lementType, []); |
| 19225 ClassElementImpl htmlDocumentElement = ElementFactory.classElement("HtmlDocu
ment", documentElement.type, []); | 19337 ClassElementImpl htmlDocumentElement = ElementFactory.classElement("HtmlDocu
ment", documentElement.type, []); |
| 19226 htmlDocumentElement.methods = <MethodElement> [ElementFactory.methodElement(
"query", elementType, <Type2> [provider.stringType])]; | 19338 htmlDocumentElement.methods = <MethodElement> [ElementFactory.methodElement(
"query", elementType, <Type2> [provider.stringType])]; |
| 19227 htmlUnit.types = <ClassElement> [ | 19339 htmlUnit.types = <ClassElement> [ |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19551 Object visitFunctionDeclaration(FunctionDeclaration node) { | 19663 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 19552 node.visitChildren(this); | 19664 node.visitChildren(this); |
| 19553 if (node.element is LibraryElement) { | 19665 if (node.element is LibraryElement) { |
| 19554 _wrongTypedNodes.add(node); | 19666 _wrongTypedNodes.add(node); |
| 19555 } | 19667 } |
| 19556 return null; | 19668 return null; |
| 19557 } | 19669 } |
| 19558 | 19670 |
| 19559 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 19671 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 19560 node.visitChildren(this); | 19672 node.visitChildren(this); |
| 19673 // TODO(brianwilkerson) If we start resolving function expressions, then con
ditionally check to |
| 19674 // see whether the node was resolved correctly. |
| 19561 return null; | 19675 return null; |
| 19562 } | 19676 } |
| 19563 | 19677 |
| 19564 Object visitImportDirective(ImportDirective node) { | 19678 Object visitImportDirective(ImportDirective node) { |
| 19679 // Not sure how to test the combinators given that it isn't an error if the
names are not defined. |
| 19565 checkResolved2(node, node.element, ImportElement); | 19680 checkResolved2(node, node.element, ImportElement); |
| 19566 SimpleIdentifier prefix = node.prefix; | 19681 SimpleIdentifier prefix = node.prefix; |
| 19567 if (prefix == null) { | 19682 if (prefix == null) { |
| 19568 return null; | 19683 return null; |
| 19569 } | 19684 } |
| 19570 return checkResolved2(prefix, prefix.staticElement, PrefixElement); | 19685 return checkResolved2(prefix, prefix.staticElement, PrefixElement); |
| 19571 } | 19686 } |
| 19572 | 19687 |
| 19573 Object visitIndexExpression(IndexExpression node) { | 19688 Object visitIndexExpression(IndexExpression node) { |
| 19574 node.visitChildren(this); | 19689 node.visitChildren(this); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19658 } | 19773 } |
| 19659 } else if (expectedClass != null) { | 19774 } else if (expectedClass != null) { |
| 19660 if (!isInstanceOf(element, expectedClass)) { | 19775 if (!isInstanceOf(element, expectedClass)) { |
| 19661 _wrongTypedNodes.add(node); | 19776 _wrongTypedNodes.add(node); |
| 19662 } | 19777 } |
| 19663 } | 19778 } |
| 19664 return null; | 19779 return null; |
| 19665 } | 19780 } |
| 19666 | 19781 |
| 19667 String getFileName(ASTNode node) { | 19782 String getFileName(ASTNode node) { |
| 19783 // TODO (jwren) there are two copies of this method, one here and one in Sta
ticTypeVerifier, |
| 19784 // they should be resolved into a single method |
| 19668 if (node != null) { | 19785 if (node != null) { |
| 19669 ASTNode root = node.root; | 19786 ASTNode root = node.root; |
| 19670 if (root is CompilationUnit) { | 19787 if (root is CompilationUnit) { |
| 19671 CompilationUnit rootCU = root; | 19788 CompilationUnit rootCU = root; |
| 19672 if (rootCU.element != null) { | 19789 if (rootCU.element != null) { |
| 19673 return rootCU.element.source.fullName; | 19790 return rootCU.element.source.fullName; |
| 19674 } else { | 19791 } else { |
| 19675 return "<unknown file- CompilationUnit.getElement() returned null>"; | 19792 return "<unknown file- CompilationUnit.getElement() returned null>"; |
| 19676 } | 19793 } |
| 19677 } else { | 19794 } else { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19839 _listener.assertNoErrors(); | 19956 _listener.assertNoErrors(); |
| 19840 } | 19957 } |
| 19841 | 19958 |
| 19842 void setUp() { | 19959 void setUp() { |
| 19843 _listener = new GatheringErrorListener(); | 19960 _listener = new GatheringErrorListener(); |
| 19844 _typeProvider = new TestTypeProvider(); | 19961 _typeProvider = new TestTypeProvider(); |
| 19845 _analyzer = createAnalyzer(); | 19962 _analyzer = createAnalyzer(); |
| 19846 } | 19963 } |
| 19847 | 19964 |
| 19848 void test_visitAdjacentStrings() { | 19965 void test_visitAdjacentStrings() { |
| 19966 // "a" "b" |
| 19849 Expression node = ASTFactory.adjacentStrings([resolvedString("a"), resolvedS
tring("b")]); | 19967 Expression node = ASTFactory.adjacentStrings([resolvedString("a"), resolvedS
tring("b")]); |
| 19850 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); | 19968 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); |
| 19851 _listener.assertNoErrors(); | 19969 _listener.assertNoErrors(); |
| 19852 } | 19970 } |
| 19853 | 19971 |
| 19854 void test_visitArgumentDefinitionTest() { | 19972 void test_visitArgumentDefinitionTest() { |
| 19973 // ?p |
| 19855 Expression node = ASTFactory.argumentDefinitionTest("p"); | 19974 Expression node = ASTFactory.argumentDefinitionTest("p"); |
| 19856 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 19975 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19857 _listener.assertNoErrors(); | 19976 _listener.assertNoErrors(); |
| 19858 } | 19977 } |
| 19859 | 19978 |
| 19860 void test_visitAsExpression() { | 19979 void test_visitAsExpression() { |
| 19980 // class A { ... this as B ... } |
| 19981 // class B extends A {} |
| 19861 ClassElement superclass = ElementFactory.classElement2("A", []); | 19982 ClassElement superclass = ElementFactory.classElement2("A", []); |
| 19862 InterfaceType superclassType = superclass.type; | 19983 InterfaceType superclassType = superclass.type; |
| 19863 ClassElement subclass = ElementFactory.classElement("B", superclassType, [])
; | 19984 ClassElement subclass = ElementFactory.classElement("B", superclassType, [])
; |
| 19864 Expression node = ASTFactory.asExpression(ASTFactory.thisExpression(), ASTFa
ctory.typeName(subclass, [])); | 19985 Expression node = ASTFactory.asExpression(ASTFactory.thisExpression(), ASTFa
ctory.typeName(subclass, [])); |
| 19865 JUnitTestCase.assertSame(subclass.type, analyze2(node, superclassType)); | 19986 JUnitTestCase.assertSame(subclass.type, analyze2(node, superclassType)); |
| 19866 _listener.assertNoErrors(); | 19987 _listener.assertNoErrors(); |
| 19867 } | 19988 } |
| 19868 | 19989 |
| 19869 void test_visitAssignmentExpression_compound() { | 19990 void test_visitAssignmentExpression_compound() { |
| 19991 // i += 1 |
| 19870 InterfaceType numType = _typeProvider.numType; | 19992 InterfaceType numType = _typeProvider.numType; |
| 19871 SimpleIdentifier identifier = resolvedVariable(_typeProvider.intType, "i"); | 19993 SimpleIdentifier identifier = resolvedVariable(_typeProvider.intType, "i"); |
| 19872 AssignmentExpression node = ASTFactory.assignmentExpression(identifier, Toke
nType.PLUS_EQ, resolvedInteger(1)); | 19994 AssignmentExpression node = ASTFactory.assignmentExpression(identifier, Toke
nType.PLUS_EQ, resolvedInteger(1)); |
| 19873 MethodElement plusMethod = getMethod(numType, "+"); | 19995 MethodElement plusMethod = getMethod(numType, "+"); |
| 19874 node.staticElement = plusMethod; | 19996 node.staticElement = plusMethod; |
| 19875 JUnitTestCase.assertSame(numType, analyze(node)); | 19997 JUnitTestCase.assertSame(numType, analyze(node)); |
| 19876 _listener.assertNoErrors(); | 19998 _listener.assertNoErrors(); |
| 19877 } | 19999 } |
| 19878 | 20000 |
| 19879 void test_visitAssignmentExpression_simple() { | 20001 void test_visitAssignmentExpression_simple() { |
| 20002 // i = 0 |
| 19880 InterfaceType intType = _typeProvider.intType; | 20003 InterfaceType intType = _typeProvider.intType; |
| 19881 Expression node = ASTFactory.assignmentExpression(resolvedVariable(intType,
"i"), TokenType.EQ, resolvedInteger(0)); | 20004 Expression node = ASTFactory.assignmentExpression(resolvedVariable(intType,
"i"), TokenType.EQ, resolvedInteger(0)); |
| 19882 JUnitTestCase.assertSame(intType, analyze(node)); | 20005 JUnitTestCase.assertSame(intType, analyze(node)); |
| 19883 _listener.assertNoErrors(); | 20006 _listener.assertNoErrors(); |
| 19884 } | 20007 } |
| 19885 | 20008 |
| 19886 void test_visitBinaryExpression_equals() { | 20009 void test_visitBinaryExpression_equals() { |
| 20010 // 2 == 3 |
| 19887 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType.
EQ_EQ, resolvedInteger(3)); | 20011 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType.
EQ_EQ, resolvedInteger(3)); |
| 19888 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20012 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19889 _listener.assertNoErrors(); | 20013 _listener.assertNoErrors(); |
| 19890 } | 20014 } |
| 19891 | 20015 |
| 19892 void test_visitBinaryExpression_logicalAnd() { | 20016 void test_visitBinaryExpression_logicalAnd() { |
| 20017 // false && true |
| 19893 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals
e), TokenType.AMPERSAND_AMPERSAND, ASTFactory.booleanLiteral(true)); | 20018 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals
e), TokenType.AMPERSAND_AMPERSAND, ASTFactory.booleanLiteral(true)); |
| 19894 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20019 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19895 _listener.assertNoErrors(); | 20020 _listener.assertNoErrors(); |
| 19896 } | 20021 } |
| 19897 | 20022 |
| 19898 void test_visitBinaryExpression_logicalOr() { | 20023 void test_visitBinaryExpression_logicalOr() { |
| 20024 // false || true |
| 19899 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals
e), TokenType.BAR_BAR, ASTFactory.booleanLiteral(true)); | 20025 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals
e), TokenType.BAR_BAR, ASTFactory.booleanLiteral(true)); |
| 19900 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20026 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19901 _listener.assertNoErrors(); | 20027 _listener.assertNoErrors(); |
| 19902 } | 20028 } |
| 19903 | 20029 |
| 19904 void test_visitBinaryExpression_notEquals() { | 20030 void test_visitBinaryExpression_notEquals() { |
| 20031 // 2 != 3 |
| 19905 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType.
BANG_EQ, resolvedInteger(3)); | 20032 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType.
BANG_EQ, resolvedInteger(3)); |
| 19906 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20033 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19907 _listener.assertNoErrors(); | 20034 _listener.assertNoErrors(); |
| 19908 } | 20035 } |
| 19909 | 20036 |
| 19910 void test_visitBinaryExpression_plusID() { | 20037 void test_visitBinaryExpression_plusID() { |
| 20038 // 1 + 2.0 |
| 19911 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedDouble(2.0)); | 20039 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedDouble(2.0)); |
| 19912 node.staticElement = getMethod(_typeProvider.numType, "+"); | 20040 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 19913 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); | 20041 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); |
| 19914 _listener.assertNoErrors(); | 20042 _listener.assertNoErrors(); |
| 19915 } | 20043 } |
| 19916 | 20044 |
| 19917 void test_visitBinaryExpression_plusII() { | 20045 void test_visitBinaryExpression_plusII() { |
| 20046 // 1 + 2 |
| 19918 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedInteger(2)); | 20047 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedInteger(2)); |
| 19919 node.staticElement = getMethod(_typeProvider.numType, "+"); | 20048 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 19920 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20049 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 19921 _listener.assertNoErrors(); | 20050 _listener.assertNoErrors(); |
| 19922 } | 20051 } |
| 19923 | 20052 |
| 19924 void test_visitBinaryExpression_slash() { | 20053 void test_visitBinaryExpression_slash() { |
| 20054 // 2 / 2 |
| 19925 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(2), Toke
nType.SLASH, resolvedInteger(2)); | 20055 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(2), Toke
nType.SLASH, resolvedInteger(2)); |
| 19926 node.staticElement = getMethod(_typeProvider.numType, "/"); | 20056 node.staticElement = getMethod(_typeProvider.numType, "/"); |
| 19927 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); | 20057 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); |
| 19928 _listener.assertNoErrors(); | 20058 _listener.assertNoErrors(); |
| 19929 } | 20059 } |
| 19930 | 20060 |
| 19931 void test_visitBinaryExpression_star_notSpecial() { | 20061 void test_visitBinaryExpression_star_notSpecial() { |
| 20062 // class A { |
| 20063 // A operator *(double value); |
| 20064 // } |
| 20065 // (a as A) * 2.0 |
| 19932 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 20066 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 19933 InterfaceType typeA = classA.type; | 20067 InterfaceType typeA = classA.type; |
| 19934 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv
ider.doubleType]); | 20068 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv
ider.doubleType]); |
| 19935 classA.methods = <MethodElement> [operator]; | 20069 classA.methods = <MethodElement> [operator]; |
| 19936 BinaryExpression node = ASTFactory.binaryExpression(ASTFactory.asExpression(
ASTFactory.identifier3("a"), ASTFactory.typeName(classA, [])), TokenType.PLUS, r
esolvedDouble(2.0)); | 20070 BinaryExpression node = ASTFactory.binaryExpression(ASTFactory.asExpression(
ASTFactory.identifier3("a"), ASTFactory.typeName(classA, [])), TokenType.PLUS, r
esolvedDouble(2.0)); |
| 19937 node.staticElement = operator; | 20071 node.staticElement = operator; |
| 19938 JUnitTestCase.assertSame(typeA, analyze(node)); | 20072 JUnitTestCase.assertSame(typeA, analyze(node)); |
| 19939 _listener.assertNoErrors(); | 20073 _listener.assertNoErrors(); |
| 19940 } | 20074 } |
| 19941 | 20075 |
| 19942 void test_visitBinaryExpression_starID() { | 20076 void test_visitBinaryExpression_starID() { |
| 20077 // 1 * 2.0 |
| 19943 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedDouble(2.0)); | 20078 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(1), Toke
nType.PLUS, resolvedDouble(2.0)); |
| 19944 node.staticElement = getMethod(_typeProvider.numType, "*"); | 20079 node.staticElement = getMethod(_typeProvider.numType, "*"); |
| 19945 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); | 20080 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); |
| 19946 _listener.assertNoErrors(); | 20081 _listener.assertNoErrors(); |
| 19947 } | 20082 } |
| 19948 | 20083 |
| 19949 void test_visitBooleanLiteral_false() { | 20084 void test_visitBooleanLiteral_false() { |
| 20085 // false |
| 19950 Expression node = ASTFactory.booleanLiteral(false); | 20086 Expression node = ASTFactory.booleanLiteral(false); |
| 19951 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20087 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19952 _listener.assertNoErrors(); | 20088 _listener.assertNoErrors(); |
| 19953 } | 20089 } |
| 19954 | 20090 |
| 19955 void test_visitBooleanLiteral_true() { | 20091 void test_visitBooleanLiteral_true() { |
| 20092 // true |
| 19956 Expression node = ASTFactory.booleanLiteral(true); | 20093 Expression node = ASTFactory.booleanLiteral(true); |
| 19957 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20094 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 19958 _listener.assertNoErrors(); | 20095 _listener.assertNoErrors(); |
| 19959 } | 20096 } |
| 19960 | 20097 |
| 19961 void test_visitCascadeExpression() { | 20098 void test_visitCascadeExpression() { |
| 20099 // a..length |
| 19962 Expression node = ASTFactory.cascadeExpression(resolvedString("a"), [ASTFact
ory.propertyAccess2(null, "length")]); | 20100 Expression node = ASTFactory.cascadeExpression(resolvedString("a"), [ASTFact
ory.propertyAccess2(null, "length")]); |
| 19963 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); | 20101 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); |
| 19964 _listener.assertNoErrors(); | 20102 _listener.assertNoErrors(); |
| 19965 } | 20103 } |
| 19966 | 20104 |
| 19967 void test_visitConditionalExpression_differentTypes() { | 20105 void test_visitConditionalExpression_differentTypes() { |
| 20106 // true ? 1.0 : 0 |
| 19968 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral
(true), resolvedDouble(1.0), resolvedInteger(0)); | 20107 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral
(true), resolvedDouble(1.0), resolvedInteger(0)); |
| 19969 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node)); | 20108 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node)); |
| 19970 _listener.assertNoErrors(); | 20109 _listener.assertNoErrors(); |
| 19971 } | 20110 } |
| 19972 | 20111 |
| 19973 void test_visitConditionalExpression_sameTypes() { | 20112 void test_visitConditionalExpression_sameTypes() { |
| 20113 // true ? 1 : 0 |
| 19974 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral
(true), resolvedInteger(1), resolvedInteger(0)); | 20114 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral
(true), resolvedInteger(1), resolvedInteger(0)); |
| 19975 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20115 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 19976 _listener.assertNoErrors(); | 20116 _listener.assertNoErrors(); |
| 19977 } | 20117 } |
| 19978 | 20118 |
| 19979 void test_visitDoubleLiteral() { | 20119 void test_visitDoubleLiteral() { |
| 20120 // 4.33 |
| 19980 Expression node = ASTFactory.doubleLiteral(4.33); | 20121 Expression node = ASTFactory.doubleLiteral(4.33); |
| 19981 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); | 20122 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node)); |
| 19982 _listener.assertNoErrors(); | 20123 _listener.assertNoErrors(); |
| 19983 } | 20124 } |
| 19984 | 20125 |
| 19985 void test_visitFunctionExpression_named_block() { | 20126 void test_visitFunctionExpression_named_block() { |
| 20127 // ({p1 : 0, p2 : 0}) {} |
| 19986 Type2 dynamicType = _typeProvider.dynamicType; | 20128 Type2 dynamicType = _typeProvider.dynamicType; |
| 19987 FormalParameter p1 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p1"), resolvedInteger(0)); | 20129 FormalParameter p1 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p1"), resolvedInteger(0)); |
| 19988 setType(p1, dynamicType); | 20130 setType(p1, dynamicType); |
| 19989 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); | 20131 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); |
| 19990 setType(p2, dynamicType); | 20132 setType(p2, dynamicType); |
| 19991 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); | 20133 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); |
| 19992 analyze3(p1); | 20134 analyze3(p1); |
| 19993 analyze3(p2); | 20135 analyze3(p2); |
| 19994 Type2 resultType = analyze(node); | 20136 Type2 resultType = analyze(node); |
| 19995 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); | 20137 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); |
| 19996 expectedNamedTypes["p1"] = dynamicType; | 20138 expectedNamedTypes["p1"] = dynamicType; |
| 19997 expectedNamedTypes["p2"] = dynamicType; | 20139 expectedNamedTypes["p2"] = dynamicType; |
| 19998 assertFunctionType(dynamicType, null, null, expectedNamedTypes, resultType); | 20140 assertFunctionType(dynamicType, null, null, expectedNamedTypes, resultType); |
| 19999 _listener.assertNoErrors(); | 20141 _listener.assertNoErrors(); |
| 20000 } | 20142 } |
| 20001 | 20143 |
| 20002 void test_visitFunctionExpression_named_expression() { | 20144 void test_visitFunctionExpression_named_expression() { |
| 20145 // ({p : 0}) -> 0; |
| 20003 Type2 dynamicType = _typeProvider.dynamicType; | 20146 Type2 dynamicType = _typeProvider.dynamicType; |
| 20004 FormalParameter p = ASTFactory.namedFormalParameter(ASTFactory.simpleFormalP
arameter3("p"), resolvedInteger(0)); | 20147 FormalParameter p = ASTFactory.namedFormalParameter(ASTFactory.simpleFormalP
arameter3("p"), resolvedInteger(0)); |
| 20005 setType(p, dynamicType); | 20148 setType(p, dynamicType); |
| 20006 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); | 20149 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); |
| 20007 analyze3(p); | 20150 analyze3(p); |
| 20008 Type2 resultType = analyze(node); | 20151 Type2 resultType = analyze(node); |
| 20009 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); | 20152 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); |
| 20010 expectedNamedTypes["p"] = dynamicType; | 20153 expectedNamedTypes["p"] = dynamicType; |
| 20011 assertFunctionType(_typeProvider.intType, null, null, expectedNamedTypes, re
sultType); | 20154 assertFunctionType(_typeProvider.intType, null, null, expectedNamedTypes, re
sultType); |
| 20012 _listener.assertNoErrors(); | 20155 _listener.assertNoErrors(); |
| 20013 } | 20156 } |
| 20014 | 20157 |
| 20015 void test_visitFunctionExpression_normal_block() { | 20158 void test_visitFunctionExpression_normal_block() { |
| 20159 // (p1, p2) {} |
| 20016 Type2 dynamicType = _typeProvider.dynamicType; | 20160 Type2 dynamicType = _typeProvider.dynamicType; |
| 20017 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); | 20161 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); |
| 20018 setType(p1, dynamicType); | 20162 setType(p1, dynamicType); |
| 20019 FormalParameter p2 = ASTFactory.simpleFormalParameter3("p2"); | 20163 FormalParameter p2 = ASTFactory.simpleFormalParameter3("p2"); |
| 20020 setType(p2, dynamicType); | 20164 setType(p2, dynamicType); |
| 20021 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); | 20165 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); |
| 20022 analyze3(p1); | 20166 analyze3(p1); |
| 20023 analyze3(p2); | 20167 analyze3(p2); |
| 20024 Type2 resultType = analyze(node); | 20168 Type2 resultType = analyze(node); |
| 20025 assertFunctionType(dynamicType, <Type2> [dynamicType, dynamicType], null, nu
ll, resultType); | 20169 assertFunctionType(dynamicType, <Type2> [dynamicType, dynamicType], null, nu
ll, resultType); |
| 20026 _listener.assertNoErrors(); | 20170 _listener.assertNoErrors(); |
| 20027 } | 20171 } |
| 20028 | 20172 |
| 20029 void test_visitFunctionExpression_normal_expression() { | 20173 void test_visitFunctionExpression_normal_expression() { |
| 20174 // (p1, p2) -> 0 |
| 20030 Type2 dynamicType = _typeProvider.dynamicType; | 20175 Type2 dynamicType = _typeProvider.dynamicType; |
| 20031 FormalParameter p = ASTFactory.simpleFormalParameter3("p"); | 20176 FormalParameter p = ASTFactory.simpleFormalParameter3("p"); |
| 20032 setType(p, dynamicType); | 20177 setType(p, dynamicType); |
| 20033 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); | 20178 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); |
| 20034 analyze3(p); | 20179 analyze3(p); |
| 20035 Type2 resultType = analyze(node); | 20180 Type2 resultType = analyze(node); |
| 20036 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], null, null,
resultType); | 20181 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], null, null,
resultType); |
| 20037 _listener.assertNoErrors(); | 20182 _listener.assertNoErrors(); |
| 20038 } | 20183 } |
| 20039 | 20184 |
| 20040 void test_visitFunctionExpression_normalAndNamed_block() { | 20185 void test_visitFunctionExpression_normalAndNamed_block() { |
| 20186 // (p1, {p2 : 0}) {} |
| 20041 Type2 dynamicType = _typeProvider.dynamicType; | 20187 Type2 dynamicType = _typeProvider.dynamicType; |
| 20042 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); | 20188 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); |
| 20043 setType(p1, dynamicType); | 20189 setType(p1, dynamicType); |
| 20044 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); | 20190 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); |
| 20045 setType(p2, dynamicType); | 20191 setType(p2, dynamicType); |
| 20046 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); | 20192 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); |
| 20047 analyze3(p2); | 20193 analyze3(p2); |
| 20048 Type2 resultType = analyze(node); | 20194 Type2 resultType = analyze(node); |
| 20049 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); | 20195 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); |
| 20050 expectedNamedTypes["p2"] = dynamicType; | 20196 expectedNamedTypes["p2"] = dynamicType; |
| 20051 assertFunctionType(dynamicType, <Type2> [dynamicType], null, expectedNamedTy
pes, resultType); | 20197 assertFunctionType(dynamicType, <Type2> [dynamicType], null, expectedNamedTy
pes, resultType); |
| 20052 _listener.assertNoErrors(); | 20198 _listener.assertNoErrors(); |
| 20053 } | 20199 } |
| 20054 | 20200 |
| 20055 void test_visitFunctionExpression_normalAndNamed_expression() { | 20201 void test_visitFunctionExpression_normalAndNamed_expression() { |
| 20202 // (p1, {p2 : 0}) -> 0 |
| 20056 Type2 dynamicType = _typeProvider.dynamicType; | 20203 Type2 dynamicType = _typeProvider.dynamicType; |
| 20057 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); | 20204 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); |
| 20058 setType(p1, dynamicType); | 20205 setType(p1, dynamicType); |
| 20059 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); | 20206 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal
Parameter3("p2"), resolvedInteger(0)); |
| 20060 setType(p2, dynamicType); | 20207 setType(p2, dynamicType); |
| 20061 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); | 20208 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); |
| 20062 analyze3(p2); | 20209 analyze3(p2); |
| 20063 Type2 resultType = analyze(node); | 20210 Type2 resultType = analyze(node); |
| 20064 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); | 20211 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>(); |
| 20065 expectedNamedTypes["p2"] = dynamicType; | 20212 expectedNamedTypes["p2"] = dynamicType; |
| 20066 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], null, expec
tedNamedTypes, resultType); | 20213 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], null, expec
tedNamedTypes, resultType); |
| 20067 _listener.assertNoErrors(); | 20214 _listener.assertNoErrors(); |
| 20068 } | 20215 } |
| 20069 | 20216 |
| 20070 void test_visitFunctionExpression_normalAndPositional_block() { | 20217 void test_visitFunctionExpression_normalAndPositional_block() { |
| 20218 // (p1, [p2 = 0]) {} |
| 20071 Type2 dynamicType = _typeProvider.dynamicType; | 20219 Type2 dynamicType = _typeProvider.dynamicType; |
| 20072 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); | 20220 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); |
| 20073 setType(p1, dynamicType); | 20221 setType(p1, dynamicType); |
| 20074 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); | 20222 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); |
| 20075 setType(p2, dynamicType); | 20223 setType(p2, dynamicType); |
| 20076 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); | 20224 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); |
| 20077 analyze3(p1); | 20225 analyze3(p1); |
| 20078 analyze3(p2); | 20226 analyze3(p2); |
| 20079 Type2 resultType = analyze(node); | 20227 Type2 resultType = analyze(node); |
| 20080 assertFunctionType(dynamicType, <Type2> [dynamicType], <Type2> [dynamicType]
, null, resultType); | 20228 assertFunctionType(dynamicType, <Type2> [dynamicType], <Type2> [dynamicType]
, null, resultType); |
| 20081 _listener.assertNoErrors(); | 20229 _listener.assertNoErrors(); |
| 20082 } | 20230 } |
| 20083 | 20231 |
| 20084 void test_visitFunctionExpression_normalAndPositional_expression() { | 20232 void test_visitFunctionExpression_normalAndPositional_expression() { |
| 20233 // (p1, [p2 = 0]) -> 0 |
| 20085 Type2 dynamicType = _typeProvider.dynamicType; | 20234 Type2 dynamicType = _typeProvider.dynamicType; |
| 20086 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); | 20235 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1"); |
| 20087 setType(p1, dynamicType); | 20236 setType(p1, dynamicType); |
| 20088 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); | 20237 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); |
| 20089 setType(p2, dynamicType); | 20238 setType(p2, dynamicType); |
| 20090 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); | 20239 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); |
| 20091 analyze3(p1); | 20240 analyze3(p1); |
| 20092 analyze3(p2); | 20241 analyze3(p2); |
| 20093 Type2 resultType = analyze(node); | 20242 Type2 resultType = analyze(node); |
| 20094 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], <Type2> [dy
namicType], null, resultType); | 20243 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType], <Type2> [dy
namicType], null, resultType); |
| 20095 _listener.assertNoErrors(); | 20244 _listener.assertNoErrors(); |
| 20096 } | 20245 } |
| 20097 | 20246 |
| 20098 void test_visitFunctionExpression_positional_block() { | 20247 void test_visitFunctionExpression_positional_block() { |
| 20248 // ([p1 = 0, p2 = 0]) {} |
| 20099 Type2 dynamicType = _typeProvider.dynamicType; | 20249 Type2 dynamicType = _typeProvider.dynamicType; |
| 20100 FormalParameter p1 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p1"), resolvedInteger(0)); | 20250 FormalParameter p1 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p1"), resolvedInteger(0)); |
| 20101 setType(p1, dynamicType); | 20251 setType(p1, dynamicType); |
| 20102 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); | 20252 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF
ormalParameter3("p2"), resolvedInteger(0)); |
| 20103 setType(p2, dynamicType); | 20253 setType(p2, dynamicType); |
| 20104 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); | 20254 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p1, p2]), ASTFactory.blockFunctionBody2([])); |
| 20105 analyze3(p1); | 20255 analyze3(p1); |
| 20106 analyze3(p2); | 20256 analyze3(p2); |
| 20107 Type2 resultType = analyze(node); | 20257 Type2 resultType = analyze(node); |
| 20108 assertFunctionType(dynamicType, null, <Type2> [dynamicType, dynamicType], nu
ll, resultType); | 20258 assertFunctionType(dynamicType, null, <Type2> [dynamicType, dynamicType], nu
ll, resultType); |
| 20109 _listener.assertNoErrors(); | 20259 _listener.assertNoErrors(); |
| 20110 } | 20260 } |
| 20111 | 20261 |
| 20112 void test_visitFunctionExpression_positional_expression() { | 20262 void test_visitFunctionExpression_positional_expression() { |
| 20263 // ([p1 = 0, p2 = 0]) -> 0 |
| 20113 Type2 dynamicType = _typeProvider.dynamicType; | 20264 Type2 dynamicType = _typeProvider.dynamicType; |
| 20114 FormalParameter p = ASTFactory.positionalFormalParameter(ASTFactory.simpleFo
rmalParameter3("p"), resolvedInteger(0)); | 20265 FormalParameter p = ASTFactory.positionalFormalParameter(ASTFactory.simpleFo
rmalParameter3("p"), resolvedInteger(0)); |
| 20115 setType(p, dynamicType); | 20266 setType(p, dynamicType); |
| 20116 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); | 20267 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame
terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0))); |
| 20117 analyze3(p); | 20268 analyze3(p); |
| 20118 Type2 resultType = analyze(node); | 20269 Type2 resultType = analyze(node); |
| 20119 assertFunctionType(_typeProvider.intType, null, <Type2> [dynamicType], null,
resultType); | 20270 assertFunctionType(_typeProvider.intType, null, <Type2> [dynamicType], null,
resultType); |
| 20120 _listener.assertNoErrors(); | 20271 _listener.assertNoErrors(); |
| 20121 } | 20272 } |
| 20122 | 20273 |
| 20123 void test_visitIndexExpression_getter() { | 20274 void test_visitIndexExpression_getter() { |
| 20275 // List a; |
| 20276 // a[2] |
| 20124 InterfaceType listType = _typeProvider.listType; | 20277 InterfaceType listType = _typeProvider.listType; |
| 20125 SimpleIdentifier identifier = resolvedVariable(listType, "a"); | 20278 SimpleIdentifier identifier = resolvedVariable(listType, "a"); |
| 20126 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege
r(2)); | 20279 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege
r(2)); |
| 20127 MethodElement indexMethod = listType.element.methods[0]; | 20280 MethodElement indexMethod = listType.element.methods[0]; |
| 20128 node.staticElement = indexMethod; | 20281 node.staticElement = indexMethod; |
| 20129 JUnitTestCase.assertSame(listType.typeArguments[0], analyze(node)); | 20282 JUnitTestCase.assertSame(listType.typeArguments[0], analyze(node)); |
| 20130 _listener.assertNoErrors(); | 20283 _listener.assertNoErrors(); |
| 20131 } | 20284 } |
| 20132 | 20285 |
| 20133 void test_visitIndexExpression_setter() { | 20286 void test_visitIndexExpression_setter() { |
| 20287 // List a; |
| 20288 // a[2] = 0 |
| 20134 InterfaceType listType = _typeProvider.listType; | 20289 InterfaceType listType = _typeProvider.listType; |
| 20135 SimpleIdentifier identifier = resolvedVariable(listType, "a"); | 20290 SimpleIdentifier identifier = resolvedVariable(listType, "a"); |
| 20136 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege
r(2)); | 20291 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege
r(2)); |
| 20137 MethodElement indexMethod = listType.element.methods[1]; | 20292 MethodElement indexMethod = listType.element.methods[1]; |
| 20138 node.staticElement = indexMethod; | 20293 node.staticElement = indexMethod; |
| 20139 ASTFactory.assignmentExpression(node, TokenType.EQ, ASTFactory.integer(0)); | 20294 ASTFactory.assignmentExpression(node, TokenType.EQ, ASTFactory.integer(0)); |
| 20140 JUnitTestCase.assertSame(listType.typeArguments[0], analyze(node)); | 20295 JUnitTestCase.assertSame(listType.typeArguments[0], analyze(node)); |
| 20141 _listener.assertNoErrors(); | 20296 _listener.assertNoErrors(); |
| 20142 } | 20297 } |
| 20143 | 20298 |
| 20144 void test_visitIndexExpression_typeParameters() { | 20299 void test_visitIndexExpression_typeParameters() { |
| 20300 // List<int> list = ... |
| 20301 // list[0] |
| 20145 InterfaceType intType = _typeProvider.intType; | 20302 InterfaceType intType = _typeProvider.intType; |
| 20146 InterfaceType listType = _typeProvider.listType; | 20303 InterfaceType listType = _typeProvider.listType; |
| 20304 // (int) -> E |
| 20147 MethodElement methodElement = getMethod(listType, "[]"); | 20305 MethodElement methodElement = getMethod(listType, "[]"); |
| 20306 // "list" has type List<int> |
| 20148 SimpleIdentifier identifier = ASTFactory.identifier3("list"); | 20307 SimpleIdentifier identifier = ASTFactory.identifier3("list"); |
| 20149 InterfaceType listOfIntType = listType.substitute4(<Type2> [intType]); | 20308 InterfaceType listOfIntType = listType.substitute4(<Type2> [intType]); |
| 20150 identifier.staticType = listOfIntType; | 20309 identifier.staticType = listOfIntType; |
| 20310 // list[0] has MethodElement element (int) -> E |
| 20151 IndexExpression indexExpression = ASTFactory.indexExpression(identifier, AST
Factory.integer(0)); | 20311 IndexExpression indexExpression = ASTFactory.indexExpression(identifier, AST
Factory.integer(0)); |
| 20152 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 20312 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 20153 indexExpression.staticElement = indexMethod; | 20313 indexExpression.staticElement = indexMethod; |
| 20314 // analyze and assert result of the index expression |
| 20154 JUnitTestCase.assertSame(intType, analyze(indexExpression)); | 20315 JUnitTestCase.assertSame(intType, analyze(indexExpression)); |
| 20155 _listener.assertNoErrors(); | 20316 _listener.assertNoErrors(); |
| 20156 } | 20317 } |
| 20157 | 20318 |
| 20158 void test_visitIndexExpression_typeParameters_inSetterContext() { | 20319 void test_visitIndexExpression_typeParameters_inSetterContext() { |
| 20320 // List<int> list = ... |
| 20321 // list[0] = 0; |
| 20159 InterfaceType intType = _typeProvider.intType; | 20322 InterfaceType intType = _typeProvider.intType; |
| 20160 InterfaceType listType = _typeProvider.listType; | 20323 InterfaceType listType = _typeProvider.listType; |
| 20324 // (int, E) -> void |
| 20161 MethodElement methodElement = getMethod(listType, "[]="); | 20325 MethodElement methodElement = getMethod(listType, "[]="); |
| 20326 // "list" has type List<int> |
| 20162 SimpleIdentifier identifier = ASTFactory.identifier3("list"); | 20327 SimpleIdentifier identifier = ASTFactory.identifier3("list"); |
| 20163 InterfaceType listOfIntType = listType.substitute4(<Type2> [intType]); | 20328 InterfaceType listOfIntType = listType.substitute4(<Type2> [intType]); |
| 20164 identifier.staticType = listOfIntType; | 20329 identifier.staticType = listOfIntType; |
| 20330 // list[0] has MethodElement element (int) -> E |
| 20165 IndexExpression indexExpression = ASTFactory.indexExpression(identifier, AST
Factory.integer(0)); | 20331 IndexExpression indexExpression = ASTFactory.indexExpression(identifier, AST
Factory.integer(0)); |
| 20166 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 20332 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 20167 indexExpression.staticElement = indexMethod; | 20333 indexExpression.staticElement = indexMethod; |
| 20334 // list[0] should be in a setter context |
| 20168 ASTFactory.assignmentExpression(indexExpression, TokenType.EQ, ASTFactory.in
teger(0)); | 20335 ASTFactory.assignmentExpression(indexExpression, TokenType.EQ, ASTFactory.in
teger(0)); |
| 20336 // analyze and assert result of the index expression |
| 20169 JUnitTestCase.assertSame(intType, analyze(indexExpression)); | 20337 JUnitTestCase.assertSame(intType, analyze(indexExpression)); |
| 20170 _listener.assertNoErrors(); | 20338 _listener.assertNoErrors(); |
| 20171 } | 20339 } |
| 20172 | 20340 |
| 20173 void test_visitInstanceCreationExpression_named() { | 20341 void test_visitInstanceCreationExpression_named() { |
| 20342 // new C.m() |
| 20174 ClassElementImpl classElement = ElementFactory.classElement2("C", []); | 20343 ClassElementImpl classElement = ElementFactory.classElement2("C", []); |
| 20175 String constructorName = "m"; | 20344 String constructorName = "m"; |
| 20176 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, constructorName, []); | 20345 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, constructorName, []); |
| 20177 constructor.returnType = classElement.type; | 20346 constructor.returnType = classElement.type; |
| 20178 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 20347 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 20179 constructor.type = constructorType; | 20348 constructor.type = constructorType; |
| 20180 classElement.constructors = <ConstructorElement> [constructor]; | 20349 classElement.constructors = <ConstructorElement> [constructor]; |
| 20181 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, ASTFactory.typeName(classElement, []), [ASTFactory.identifier3(constructorNam
e)]); | 20350 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, ASTFactory.typeName(classElement, []), [ASTFactory.identifier3(constructorNam
e)]); |
| 20182 node.staticElement = constructor; | 20351 node.staticElement = constructor; |
| 20183 JUnitTestCase.assertSame(classElement.type, analyze(node)); | 20352 JUnitTestCase.assertSame(classElement.type, analyze(node)); |
| 20184 _listener.assertNoErrors(); | 20353 _listener.assertNoErrors(); |
| 20185 } | 20354 } |
| 20186 | 20355 |
| 20187 void test_visitInstanceCreationExpression_typeParameters() { | 20356 void test_visitInstanceCreationExpression_typeParameters() { |
| 20357 // new C<I>() |
| 20188 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); | 20358 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); |
| 20189 ClassElementImpl elementI = ElementFactory.classElement2("I", []); | 20359 ClassElementImpl elementI = ElementFactory.classElement2("I", []); |
| 20190 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem
entC, null, []); | 20360 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem
entC, null, []); |
| 20191 elementC.constructors = <ConstructorElement> [constructor]; | 20361 elementC.constructors = <ConstructorElement> [constructor]; |
| 20192 constructor.returnType = elementC.type; | 20362 constructor.returnType = elementC.type; |
| 20193 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 20363 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 20194 constructor.type = constructorType; | 20364 constructor.type = constructorType; |
| 20195 TypeName typeName = ASTFactory.typeName(elementC, [ASTFactory.typeName(eleme
ntI, [])]); | 20365 TypeName typeName = ASTFactory.typeName(elementC, [ASTFactory.typeName(eleme
ntI, [])]); |
| 20196 typeName.type = elementC.type.substitute4(<Type2> [elementI.type]); | 20366 typeName.type = elementC.type.substitute4(<Type2> [elementI.type]); |
| 20197 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, typeName, []); | 20367 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, typeName, []); |
| 20198 node.staticElement = constructor; | 20368 node.staticElement = constructor; |
| 20199 InterfaceType interfaceType = analyze(node) as InterfaceType; | 20369 InterfaceType interfaceType = analyze(node) as InterfaceType; |
| 20200 List<Type2> typeArgs = interfaceType.typeArguments; | 20370 List<Type2> typeArgs = interfaceType.typeArguments; |
| 20201 JUnitTestCase.assertEquals(1, typeArgs.length); | 20371 JUnitTestCase.assertEquals(1, typeArgs.length); |
| 20202 JUnitTestCase.assertEquals(elementI.type, typeArgs[0]); | 20372 JUnitTestCase.assertEquals(elementI.type, typeArgs[0]); |
| 20203 _listener.assertNoErrors(); | 20373 _listener.assertNoErrors(); |
| 20204 } | 20374 } |
| 20205 | 20375 |
| 20206 void test_visitInstanceCreationExpression_unnamed() { | 20376 void test_visitInstanceCreationExpression_unnamed() { |
| 20377 // new C() |
| 20207 ClassElementImpl classElement = ElementFactory.classElement2("C", []); | 20378 ClassElementImpl classElement = ElementFactory.classElement2("C", []); |
| 20208 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, null, []); | 20379 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, null, []); |
| 20209 constructor.returnType = classElement.type; | 20380 constructor.returnType = classElement.type; |
| 20210 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 20381 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 20211 constructor.type = constructorType; | 20382 constructor.type = constructorType; |
| 20212 classElement.constructors = <ConstructorElement> [constructor]; | 20383 classElement.constructors = <ConstructorElement> [constructor]; |
| 20213 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, ASTFactory.typeName(classElement, []), []); | 20384 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul
l, ASTFactory.typeName(classElement, []), []); |
| 20214 node.staticElement = constructor; | 20385 node.staticElement = constructor; |
| 20215 JUnitTestCase.assertSame(classElement.type, analyze(node)); | 20386 JUnitTestCase.assertSame(classElement.type, analyze(node)); |
| 20216 _listener.assertNoErrors(); | 20387 _listener.assertNoErrors(); |
| 20217 } | 20388 } |
| 20218 | 20389 |
| 20219 void test_visitIntegerLiteral() { | 20390 void test_visitIntegerLiteral() { |
| 20391 // 42 |
| 20220 Expression node = resolvedInteger(42); | 20392 Expression node = resolvedInteger(42); |
| 20221 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20393 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20222 _listener.assertNoErrors(); | 20394 _listener.assertNoErrors(); |
| 20223 } | 20395 } |
| 20224 | 20396 |
| 20225 void test_visitIsExpression_negated() { | 20397 void test_visitIsExpression_negated() { |
| 20398 // a is! String |
| 20226 Expression node = ASTFactory.isExpression(resolvedString("a"), true, ASTFact
ory.typeName4("String", [])); | 20399 Expression node = ASTFactory.isExpression(resolvedString("a"), true, ASTFact
ory.typeName4("String", [])); |
| 20227 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20400 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 20228 _listener.assertNoErrors(); | 20401 _listener.assertNoErrors(); |
| 20229 } | 20402 } |
| 20230 | 20403 |
| 20231 void test_visitIsExpression_notNegated() { | 20404 void test_visitIsExpression_notNegated() { |
| 20405 // a is String |
| 20232 Expression node = ASTFactory.isExpression(resolvedString("a"), false, ASTFac
tory.typeName4("String", [])); | 20406 Expression node = ASTFactory.isExpression(resolvedString("a"), false, ASTFac
tory.typeName4("String", [])); |
| 20233 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20407 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 20234 _listener.assertNoErrors(); | 20408 _listener.assertNoErrors(); |
| 20235 } | 20409 } |
| 20236 | 20410 |
| 20237 void test_visitListLiteral_empty() { | 20411 void test_visitListLiteral_empty() { |
| 20412 // [] |
| 20238 Expression node = ASTFactory.listLiteral([]); | 20413 Expression node = ASTFactory.listLiteral([]); |
| 20239 Type2 resultType = analyze(node); | 20414 Type2 resultType = analyze(node); |
| 20240 assertType2(_typeProvider.listType.substitute4(<Type2> [_typeProvider.dynami
cType]), resultType); | 20415 assertType2(_typeProvider.listType.substitute4(<Type2> [_typeProvider.dynami
cType]), resultType); |
| 20241 _listener.assertNoErrors(); | 20416 _listener.assertNoErrors(); |
| 20242 } | 20417 } |
| 20243 | 20418 |
| 20244 void test_visitListLiteral_nonEmpty() { | 20419 void test_visitListLiteral_nonEmpty() { |
| 20420 // [0] |
| 20245 Expression node = ASTFactory.listLiteral([resolvedInteger(0)]); | 20421 Expression node = ASTFactory.listLiteral([resolvedInteger(0)]); |
| 20246 Type2 resultType = analyze(node); | 20422 Type2 resultType = analyze(node); |
| 20247 assertType2(_typeProvider.listType.substitute4(<Type2> [_typeProvider.dynami
cType]), resultType); | 20423 assertType2(_typeProvider.listType.substitute4(<Type2> [_typeProvider.dynami
cType]), resultType); |
| 20248 _listener.assertNoErrors(); | 20424 _listener.assertNoErrors(); |
| 20249 } | 20425 } |
| 20250 | 20426 |
| 20251 void test_visitMapLiteral_empty() { | 20427 void test_visitMapLiteral_empty() { |
| 20428 // {} |
| 20252 Expression node = ASTFactory.mapLiteral2([]); | 20429 Expression node = ASTFactory.mapLiteral2([]); |
| 20253 Type2 resultType = analyze(node); | 20430 Type2 resultType = analyze(node); |
| 20254 assertType2(_typeProvider.mapType.substitute4(<Type2> [_typeProvider.dynamic
Type, _typeProvider.dynamicType]), resultType); | 20431 assertType2(_typeProvider.mapType.substitute4(<Type2> [_typeProvider.dynamic
Type, _typeProvider.dynamicType]), resultType); |
| 20255 _listener.assertNoErrors(); | 20432 _listener.assertNoErrors(); |
| 20256 } | 20433 } |
| 20257 | 20434 |
| 20258 void test_visitMapLiteral_nonEmpty() { | 20435 void test_visitMapLiteral_nonEmpty() { |
| 20436 // {"k" : 0} |
| 20259 Expression node = ASTFactory.mapLiteral2([ASTFactory.mapLiteralEntry("k", re
solvedInteger(0))]); | 20437 Expression node = ASTFactory.mapLiteral2([ASTFactory.mapLiteralEntry("k", re
solvedInteger(0))]); |
| 20260 Type2 resultType = analyze(node); | 20438 Type2 resultType = analyze(node); |
| 20261 assertType2(_typeProvider.mapType.substitute4(<Type2> [_typeProvider.dynamic
Type, _typeProvider.dynamicType]), resultType); | 20439 assertType2(_typeProvider.mapType.substitute4(<Type2> [_typeProvider.dynamic
Type, _typeProvider.dynamicType]), resultType); |
| 20262 _listener.assertNoErrors(); | 20440 _listener.assertNoErrors(); |
| 20263 } | 20441 } |
| 20264 | 20442 |
| 20265 void test_visitMethodInvocation_then() { | 20443 void test_visitMethodInvocation_then() { |
| 20444 // then() |
| 20266 Expression node = ASTFactory.methodInvocation(null, "then", []); | 20445 Expression node = ASTFactory.methodInvocation(null, "then", []); |
| 20267 analyze(node); | 20446 analyze(node); |
| 20268 _listener.assertNoErrors(); | 20447 _listener.assertNoErrors(); |
| 20269 } | 20448 } |
| 20270 | 20449 |
| 20271 void test_visitNamedExpression() { | 20450 void test_visitNamedExpression() { |
| 20451 // n: a |
| 20272 Expression node = ASTFactory.namedExpression2("n", resolvedString("a")); | 20452 Expression node = ASTFactory.namedExpression2("n", resolvedString("a")); |
| 20273 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); | 20453 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); |
| 20274 _listener.assertNoErrors(); | 20454 _listener.assertNoErrors(); |
| 20275 } | 20455 } |
| 20276 | 20456 |
| 20277 void test_visitNullLiteral() { | 20457 void test_visitNullLiteral() { |
| 20458 // null |
| 20278 Expression node = ASTFactory.nullLiteral(); | 20459 Expression node = ASTFactory.nullLiteral(); |
| 20279 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); | 20460 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); |
| 20280 _listener.assertNoErrors(); | 20461 _listener.assertNoErrors(); |
| 20281 } | 20462 } |
| 20282 | 20463 |
| 20283 void test_visitParenthesizedExpression() { | 20464 void test_visitParenthesizedExpression() { |
| 20465 // (0) |
| 20284 Expression node = ASTFactory.parenthesizedExpression(resolvedInteger(0)); | 20466 Expression node = ASTFactory.parenthesizedExpression(resolvedInteger(0)); |
| 20285 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20467 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20286 _listener.assertNoErrors(); | 20468 _listener.assertNoErrors(); |
| 20287 } | 20469 } |
| 20288 | 20470 |
| 20289 void test_visitPostfixExpression_minusMinus() { | 20471 void test_visitPostfixExpression_minusMinus() { |
| 20472 // 0-- |
| 20290 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To
kenType.MINUS_MINUS); | 20473 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To
kenType.MINUS_MINUS); |
| 20291 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20474 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20292 _listener.assertNoErrors(); | 20475 _listener.assertNoErrors(); |
| 20293 } | 20476 } |
| 20294 | 20477 |
| 20295 void test_visitPostfixExpression_plusPlus() { | 20478 void test_visitPostfixExpression_plusPlus() { |
| 20479 // 0++ |
| 20296 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To
kenType.PLUS_PLUS); | 20480 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To
kenType.PLUS_PLUS); |
| 20297 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20481 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20298 _listener.assertNoErrors(); | 20482 _listener.assertNoErrors(); |
| 20299 } | 20483 } |
| 20300 | 20484 |
| 20301 void test_visitPrefixedIdentifier_getter() { | 20485 void test_visitPrefixedIdentifier_getter() { |
| 20302 Type2 boolType = _typeProvider.boolType; | 20486 Type2 boolType = _typeProvider.boolType; |
| 20303 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); | 20487 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); |
| 20304 PrefixedIdentifier node = ASTFactory.identifier5("a", "b"); | 20488 PrefixedIdentifier node = ASTFactory.identifier5("a", "b"); |
| 20305 node.identifier.staticElement = getter; | 20489 node.identifier.staticElement = getter; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 20320 void test_visitPrefixedIdentifier_variable() { | 20504 void test_visitPrefixedIdentifier_variable() { |
| 20321 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); | 20505 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); |
| 20322 variable.type = _typeProvider.boolType; | 20506 variable.type = _typeProvider.boolType; |
| 20323 PrefixedIdentifier node = ASTFactory.identifier5("a", "b"); | 20507 PrefixedIdentifier node = ASTFactory.identifier5("a", "b"); |
| 20324 node.identifier.staticElement = variable; | 20508 node.identifier.staticElement = variable; |
| 20325 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20509 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 20326 _listener.assertNoErrors(); | 20510 _listener.assertNoErrors(); |
| 20327 } | 20511 } |
| 20328 | 20512 |
| 20329 void test_visitPrefixExpression_bang() { | 20513 void test_visitPrefixExpression_bang() { |
| 20514 // !0 |
| 20330 PrefixExpression node = ASTFactory.prefixExpression(TokenType.BANG, resolved
Integer(0)); | 20515 PrefixExpression node = ASTFactory.prefixExpression(TokenType.BANG, resolved
Integer(0)); |
| 20331 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20516 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 20332 _listener.assertNoErrors(); | 20517 _listener.assertNoErrors(); |
| 20333 } | 20518 } |
| 20334 | 20519 |
| 20335 void test_visitPrefixExpression_minus() { | 20520 void test_visitPrefixExpression_minus() { |
| 20521 // -0 |
| 20336 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS, resolve
dInteger(0)); | 20522 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS, resolve
dInteger(0)); |
| 20337 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); | 20523 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); |
| 20338 node.staticElement = minusMethod; | 20524 node.staticElement = minusMethod; |
| 20339 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node)); | 20525 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node)); |
| 20340 _listener.assertNoErrors(); | 20526 _listener.assertNoErrors(); |
| 20341 } | 20527 } |
| 20342 | 20528 |
| 20343 void test_visitPrefixExpression_minusMinus() { | 20529 void test_visitPrefixExpression_minusMinus() { |
| 20530 // --0 |
| 20344 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS_MINUS, r
esolvedInteger(0)); | 20531 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS_MINUS, r
esolvedInteger(0)); |
| 20345 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); | 20532 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); |
| 20346 node.staticElement = minusMethod; | 20533 node.staticElement = minusMethod; |
| 20347 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20534 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20348 _listener.assertNoErrors(); | 20535 _listener.assertNoErrors(); |
| 20349 } | 20536 } |
| 20350 | 20537 |
| 20351 void test_visitPrefixExpression_not() { | 20538 void test_visitPrefixExpression_not() { |
| 20539 // !true |
| 20352 Expression node = ASTFactory.prefixExpression(TokenType.BANG, ASTFactory.boo
leanLiteral(true)); | 20540 Expression node = ASTFactory.prefixExpression(TokenType.BANG, ASTFactory.boo
leanLiteral(true)); |
| 20353 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); | 20541 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node)); |
| 20354 _listener.assertNoErrors(); | 20542 _listener.assertNoErrors(); |
| 20355 } | 20543 } |
| 20356 | 20544 |
| 20357 void test_visitPrefixExpression_plusPlus() { | 20545 void test_visitPrefixExpression_plusPlus() { |
| 20546 // ++0 |
| 20358 PrefixExpression node = ASTFactory.prefixExpression(TokenType.PLUS_PLUS, res
olvedInteger(0)); | 20547 PrefixExpression node = ASTFactory.prefixExpression(TokenType.PLUS_PLUS, res
olvedInteger(0)); |
| 20359 MethodElement plusMethod = getMethod(_typeProvider.numType, "+"); | 20548 MethodElement plusMethod = getMethod(_typeProvider.numType, "+"); |
| 20360 node.staticElement = plusMethod; | 20549 node.staticElement = plusMethod; |
| 20361 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20550 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20362 _listener.assertNoErrors(); | 20551 _listener.assertNoErrors(); |
| 20363 } | 20552 } |
| 20364 | 20553 |
| 20365 void test_visitPrefixExpression_tilde() { | 20554 void test_visitPrefixExpression_tilde() { |
| 20555 // ~0 |
| 20366 PrefixExpression node = ASTFactory.prefixExpression(TokenType.TILDE, resolve
dInteger(0)); | 20556 PrefixExpression node = ASTFactory.prefixExpression(TokenType.TILDE, resolve
dInteger(0)); |
| 20367 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); | 20557 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); |
| 20368 node.staticElement = tildeMethod; | 20558 node.staticElement = tildeMethod; |
| 20369 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); | 20559 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node)); |
| 20370 _listener.assertNoErrors(); | 20560 _listener.assertNoErrors(); |
| 20371 } | 20561 } |
| 20372 | 20562 |
| 20373 void test_visitPropertyAccess_getter() { | 20563 void test_visitPropertyAccess_getter() { |
| 20374 Type2 boolType = _typeProvider.boolType; | 20564 Type2 boolType = _typeProvider.boolType; |
| 20375 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); | 20565 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); |
| 20376 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier3("a")
, "b"); | 20566 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier3("a")
, "b"); |
| 20377 node.propertyName.staticElement = getter; | 20567 node.propertyName.staticElement = getter; |
| 20378 JUnitTestCase.assertSame(boolType, analyze(node)); | 20568 JUnitTestCase.assertSame(boolType, analyze(node)); |
| 20379 _listener.assertNoErrors(); | 20569 _listener.assertNoErrors(); |
| 20380 } | 20570 } |
| 20381 | 20571 |
| 20382 void test_visitPropertyAccess_setter() { | 20572 void test_visitPropertyAccess_setter() { |
| 20383 Type2 boolType = _typeProvider.boolType; | 20573 Type2 boolType = _typeProvider.boolType; |
| 20384 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); | 20574 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); |
| 20385 PropertyAccessorElement setter = field.setter; | 20575 PropertyAccessorElement setter = field.setter; |
| 20386 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier3("a")
, "b"); | 20576 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier3("a")
, "b"); |
| 20387 node.propertyName.staticElement = setter; | 20577 node.propertyName.staticElement = setter; |
| 20388 JUnitTestCase.assertSame(boolType, analyze(node)); | 20578 JUnitTestCase.assertSame(boolType, analyze(node)); |
| 20389 _listener.assertNoErrors(); | 20579 _listener.assertNoErrors(); |
| 20390 } | 20580 } |
| 20391 | 20581 |
| 20392 void test_visitSimpleStringLiteral() { | 20582 void test_visitSimpleStringLiteral() { |
| 20583 // "a" |
| 20393 Expression node = resolvedString("a"); | 20584 Expression node = resolvedString("a"); |
| 20394 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); | 20585 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); |
| 20395 _listener.assertNoErrors(); | 20586 _listener.assertNoErrors(); |
| 20396 } | 20587 } |
| 20397 | 20588 |
| 20398 void test_visitStringInterpolation() { | 20589 void test_visitStringInterpolation() { |
| 20590 // "a${'b'}c" |
| 20399 Expression node = ASTFactory.string([ | 20591 Expression node = ASTFactory.string([ |
| 20400 ASTFactory.interpolationString("a", "a"), | 20592 ASTFactory.interpolationString("a", "a"), |
| 20401 ASTFactory.interpolationExpression(resolvedString("b")), | 20593 ASTFactory.interpolationExpression(resolvedString("b")), |
| 20402 ASTFactory.interpolationString("c", "c")]); | 20594 ASTFactory.interpolationString("c", "c")]); |
| 20403 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); | 20595 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node)); |
| 20404 _listener.assertNoErrors(); | 20596 _listener.assertNoErrors(); |
| 20405 } | 20597 } |
| 20406 | 20598 |
| 20407 void test_visitSuperExpression() { | 20599 void test_visitSuperExpression() { |
| 20600 // super |
| 20408 InterfaceType superType = ElementFactory.classElement2("A", []).type; | 20601 InterfaceType superType = ElementFactory.classElement2("A", []).type; |
| 20409 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ
e; | 20602 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ
e; |
| 20410 Expression node = ASTFactory.superExpression(); | 20603 Expression node = ASTFactory.superExpression(); |
| 20411 JUnitTestCase.assertSame(thisType, analyze2(node, thisType)); | 20604 JUnitTestCase.assertSame(thisType, analyze2(node, thisType)); |
| 20412 _listener.assertNoErrors(); | 20605 _listener.assertNoErrors(); |
| 20413 } | 20606 } |
| 20414 | 20607 |
| 20415 void test_visitSymbolLiteral() { | 20608 void test_visitSymbolLiteral() { |
| 20416 JUnitTestCase.assertSame(_typeProvider.symbolType, analyze(ASTFactory.symbol
Literal(["a"]))); | 20609 JUnitTestCase.assertSame(_typeProvider.symbolType, analyze(ASTFactory.symbol
Literal(["a"]))); |
| 20417 } | 20610 } |
| 20418 | 20611 |
| 20419 void test_visitThisExpression() { | 20612 void test_visitThisExpression() { |
| 20613 // this |
| 20420 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla
ssElement2("A", []).type, []).type; | 20614 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla
ssElement2("A", []).type, []).type; |
| 20421 Expression node = ASTFactory.thisExpression(); | 20615 Expression node = ASTFactory.thisExpression(); |
| 20422 JUnitTestCase.assertSame(thisType, analyze2(node, thisType)); | 20616 JUnitTestCase.assertSame(thisType, analyze2(node, thisType)); |
| 20423 _listener.assertNoErrors(); | 20617 _listener.assertNoErrors(); |
| 20424 } | 20618 } |
| 20425 | 20619 |
| 20426 void test_visitThrowExpression_withoutValue() { | 20620 void test_visitThrowExpression_withoutValue() { |
| 20621 // throw |
| 20427 Expression node = ASTFactory.throwExpression(); | 20622 Expression node = ASTFactory.throwExpression(); |
| 20428 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); | 20623 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); |
| 20429 _listener.assertNoErrors(); | 20624 _listener.assertNoErrors(); |
| 20430 } | 20625 } |
| 20431 | 20626 |
| 20432 void test_visitThrowExpression_withValue() { | 20627 void test_visitThrowExpression_withValue() { |
| 20628 // throw 0 |
| 20433 Expression node = ASTFactory.throwExpression2(resolvedInteger(0)); | 20629 Expression node = ASTFactory.throwExpression2(resolvedInteger(0)); |
| 20434 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); | 20630 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node)); |
| 20435 _listener.assertNoErrors(); | 20631 _listener.assertNoErrors(); |
| 20436 } | 20632 } |
| 20437 | 20633 |
| 20438 /** | 20634 /** |
| 20439 * Return the type associated with the given expression after the static type
analyzer has | 20635 * Return the type associated with the given expression after the static type
analyzer has |
| 20440 * computed a type for it. | 20636 * computed a type for it. |
| 20441 * | 20637 * |
| 20442 * @param node the expression with which the type is associated | 20638 * @param node the expression with which the type is associated |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21391 "f(var a) {", | 21587 "f(var a) {", |
| 21392 " if(a is A) {", | 21588 " if(a is A) {", |
| 21393 " a.b = 0;", | 21589 " a.b = 0;", |
| 21394 " }", | 21590 " }", |
| 21395 "}"])); | 21591 "}"])); |
| 21396 resolve(source); | 21592 resolve(source); |
| 21397 assertNoErrors(source); | 21593 assertNoErrors(source); |
| 21398 } | 21594 } |
| 21399 | 21595 |
| 21400 void test_unnecessaryCast_13855_parameter_A() { | 21596 void test_unnecessaryCast_13855_parameter_A() { |
| 21597 // dartbug.com/13855, dartbug.com/13732 |
| 21401 Source source = addSource(EngineTestCase.createSource([ | 21598 Source source = addSource(EngineTestCase.createSource([ |
| 21402 "class A{", | 21599 "class A{", |
| 21403 " a() {}", | 21600 " a() {}", |
| 21404 "}", | 21601 "}", |
| 21405 "class B<E> {", | 21602 "class B<E> {", |
| 21406 " E e;", | 21603 " E e;", |
| 21407 " m() {", | 21604 " m() {", |
| 21408 " (e as A).a();", | 21605 " (e as A).a();", |
| 21409 " }", | 21606 " }", |
| 21410 "}"])); | 21607 "}"])); |
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22576 " void m1() {}", | 22773 " void m1() {}", |
| 22577 " void m2() {}", | 22774 " void m2() {}", |
| 22578 " void m() {", | 22775 " void m() {", |
| 22579 " A a = new A();", | 22776 " A a = new A();", |
| 22580 " a..m1()", | 22777 " a..m1()", |
| 22581 " ..name = 'name'", | 22778 " ..name = 'name'", |
| 22582 " ..m2();", | 22779 " ..m2();", |
| 22583 " }", | 22780 " }", |
| 22584 "}"])); | 22781 "}"])); |
| 22585 resolve(source); | 22782 resolve(source); |
| 22783 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 22586 assertNoErrors(source); | 22784 assertNoErrors(source); |
| 22587 verify([source]); | 22785 verify([source]); |
| 22588 } | 22786 } |
| 22589 | 22787 |
| 22590 void test_resolveAgainstNull() { | 22788 void test_resolveAgainstNull() { |
| 22591 Source source = addSource(EngineTestCase.createSource(["f(var p) {", " retu
rn null == p;", "}"])); | 22789 Source source = addSource(EngineTestCase.createSource(["f(var p) {", " retu
rn null == p;", "}"])); |
| 22592 resolve(source); | 22790 resolve(source); |
| 22593 assertNoErrors(source); | 22791 assertNoErrors(source); |
| 22594 } | 22792 } |
| 22595 | 22793 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22859 List<bool> found; | 23057 List<bool> found; |
| 22860 | 23058 |
| 22861 List<AnalysisException> thrownException; | 23059 List<AnalysisException> thrownException; |
| 22862 | 23060 |
| 22863 RecursiveASTVisitor_SimpleResolverTest_test_localVariable_types_invoked(this.S
impleResolverTest_this, this.found, this.thrownException) : super(); | 23061 RecursiveASTVisitor_SimpleResolverTest_test_localVariable_types_invoked(this.S
impleResolverTest_this, this.found, this.thrownException) : super(); |
| 22864 | 23062 |
| 22865 Object visitSimpleIdentifier(SimpleIdentifier node) { | 23063 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 22866 if (node.name == "myVar" && node.parent is MethodInvocation) { | 23064 if (node.name == "myVar" && node.parent is MethodInvocation) { |
| 22867 try { | 23065 try { |
| 22868 found[0] = true; | 23066 found[0] = true; |
| 23067 // check static type |
| 22869 Type2 staticType = node.staticType; | 23068 Type2 staticType = node.staticType; |
| 22870 JUnitTestCase.assertSame(SimpleResolverTest_this.typeProvider.dynamicTyp
e, staticType); | 23069 JUnitTestCase.assertSame(SimpleResolverTest_this.typeProvider.dynamicTyp
e, staticType); |
| 23070 // check propagated type |
| 22871 FunctionType propagatedType = node.propagatedType as FunctionType; | 23071 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 22872 JUnitTestCase.assertEquals(SimpleResolverTest_this.typeProvider.stringTy
pe, propagatedType.returnType); | 23072 JUnitTestCase.assertEquals(SimpleResolverTest_this.typeProvider.stringTy
pe, propagatedType.returnType); |
| 22873 } on AnalysisException catch (e) { | 23073 } on AnalysisException catch (e) { |
| 22874 thrownException[0] = e; | 23074 thrownException[0] = e; |
| 22875 } | 23075 } |
| 22876 } | 23076 } |
| 22877 return null; | 23077 return null; |
| 22878 } | 23078 } |
| 22879 } | 23079 } |
| 22880 | 23080 |
| 22881 class SubtypeManagerTest extends EngineTestCase { | 23081 class SubtypeManagerTest extends EngineTestCase { |
| 22882 /** | 23082 /** |
| 22883 * The inheritance manager being tested. | 23083 * The inheritance manager being tested. |
| 22884 */ | 23084 */ |
| 22885 SubtypeManager _subtypeManager; | 23085 SubtypeManager _subtypeManager; |
| 22886 | 23086 |
| 22887 /** | 23087 /** |
| 22888 * The compilation unit element containing all of the types setup in each test
. | 23088 * The compilation unit element containing all of the types setup in each test
. |
| 22889 */ | 23089 */ |
| 22890 CompilationUnitElementImpl _definingCompilationUnit; | 23090 CompilationUnitElementImpl _definingCompilationUnit; |
| 22891 | 23091 |
| 22892 void test_computeAllSubtypes_infiniteLoop() { | 23092 void test_computeAllSubtypes_infiniteLoop() { |
| 23093 // |
| 23094 // class A extends B |
| 23095 // class B extends A |
| 23096 // |
| 22893 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 23097 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 22894 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 23098 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 22895 classA.supertype = classB.type; | 23099 classA.supertype = classB.type; |
| 22896 _definingCompilationUnit.types = <ClassElement> [classA, classB]; | 23100 _definingCompilationUnit.types = <ClassElement> [classA, classB]; |
| 22897 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); | 23101 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); |
| 22898 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 23102 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 22899 EngineTestCase.assertSize3(2, subtypesOfA); | 23103 EngineTestCase.assertSize3(2, subtypesOfA); |
| 22900 EngineTestCase.assertContains(arraySubtypesOfA, [classA, classB]); | 23104 EngineTestCase.assertContains(arraySubtypesOfA, [classA, classB]); |
| 22901 } | 23105 } |
| 22902 | 23106 |
| 22903 void test_computeAllSubtypes_manyRecursiveSubtypes() { | 23107 void test_computeAllSubtypes_manyRecursiveSubtypes() { |
| 23108 // |
| 23109 // class A |
| 23110 // class B extends A |
| 23111 // class C extends B |
| 23112 // class D extends B |
| 23113 // class E extends B |
| 23114 // |
| 22904 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 23115 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 22905 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 23116 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 22906 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); | 23117 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); |
| 22907 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); | 23118 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); |
| 22908 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); | 23119 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); |
| 22909 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla
ssD, classE]; | 23120 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla
ssD, classE]; |
| 22910 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); | 23121 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); |
| 22911 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 23122 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 22912 Set<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(classB); | 23123 Set<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(classB); |
| 22913 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); | 23124 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); |
| 22914 EngineTestCase.assertSize3(4, subtypesOfA); | 23125 EngineTestCase.assertSize3(4, subtypesOfA); |
| 22915 EngineTestCase.assertContains(arraySubtypesOfA, [classB, classC, classD, cla
ssE]); | 23126 EngineTestCase.assertContains(arraySubtypesOfA, [classB, classC, classD, cla
ssE]); |
| 22916 EngineTestCase.assertSize3(3, subtypesOfB); | 23127 EngineTestCase.assertSize3(3, subtypesOfB); |
| 22917 EngineTestCase.assertContains(arraySubtypesOfB, [classC, classD, classE]); | 23128 EngineTestCase.assertContains(arraySubtypesOfB, [classC, classD, classE]); |
| 22918 } | 23129 } |
| 22919 | 23130 |
| 22920 void test_computeAllSubtypes_noSubtypes() { | 23131 void test_computeAllSubtypes_noSubtypes() { |
| 23132 // |
| 23133 // class A |
| 23134 // |
| 22921 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 23135 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 22922 _definingCompilationUnit.types = <ClassElement> [classA]; | 23136 _definingCompilationUnit.types = <ClassElement> [classA]; |
| 22923 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); | 23137 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); |
| 22924 EngineTestCase.assertSize3(0, subtypesOfA); | 23138 EngineTestCase.assertSize3(0, subtypesOfA); |
| 22925 } | 23139 } |
| 22926 | 23140 |
| 22927 void test_computeAllSubtypes_oneSubtype() { | 23141 void test_computeAllSubtypes_oneSubtype() { |
| 23142 // |
| 23143 // class A |
| 23144 // class B extends A |
| 23145 // |
| 22928 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 23146 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 22929 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 23147 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 22930 _definingCompilationUnit.types = <ClassElement> [classA, classB]; | 23148 _definingCompilationUnit.types = <ClassElement> [classA, classB]; |
| 22931 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); | 23149 Set<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(classA); |
| 22932 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 23150 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 22933 EngineTestCase.assertSize3(1, subtypesOfA); | 23151 EngineTestCase.assertSize3(1, subtypesOfA); |
| 22934 EngineTestCase.assertContains(arraySubtypesOfA, [classB]); | 23152 EngineTestCase.assertContains(arraySubtypesOfA, [classB]); |
| 22935 } | 23153 } |
| 22936 | 23154 |
| 22937 void setUp() { | 23155 void setUp() { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23218 // HintCodeTest.dartSuite(); | 23436 // HintCodeTest.dartSuite(); |
| 23219 // MemberMapTest.dartSuite(); | 23437 // MemberMapTest.dartSuite(); |
| 23220 // NonHintCodeTest.dartSuite(); | 23438 // NonHintCodeTest.dartSuite(); |
| 23221 // NonErrorResolverTest.dartSuite(); | 23439 // NonErrorResolverTest.dartSuite(); |
| 23222 // SimpleResolverTest.dartSuite(); | 23440 // SimpleResolverTest.dartSuite(); |
| 23223 // StaticTypeWarningCodeTest.dartSuite(); | 23441 // StaticTypeWarningCodeTest.dartSuite(); |
| 23224 // StaticWarningCodeTest.dartSuite(); | 23442 // StaticWarningCodeTest.dartSuite(); |
| 23225 // StrictModeTest.dartSuite(); | 23443 // StrictModeTest.dartSuite(); |
| 23226 // TypePropagationTest.dartSuite(); | 23444 // TypePropagationTest.dartSuite(); |
| 23227 } | 23445 } |
| OLD | NEW |