OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library dart2js.semantics_visitor_test; | 5 library dart2js.semantics_visitor_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'package:compiler/src/constants/expressions.dart'; | 10 import 'package:compiler/src/constants/expressions.dart'; |
(...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2451 factory Class(a, b) = AbstractClass; | 2451 factory Class(a, b) = AbstractClass; |
2452 } | 2452 } |
2453 m() => new Class(true, 42); | 2453 m() => new Class(true, 42); |
2454 ''', | 2454 ''', |
2455 const Visit( | 2455 const Visit( |
2456 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, | 2456 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, |
2457 element: 'function(Class#)', | 2457 element: 'function(Class#)', |
2458 arguments: '(true,42)', | 2458 arguments: '(true,42)', |
2459 type: 'Class', | 2459 type: 'Class', |
2460 selector: 'CallStructure(arity=2)')), | 2460 selector: 'CallStructure(arity=2)')), |
| 2461 const Test( |
| 2462 ''' |
| 2463 class Class {} |
| 2464 m() => const Class(); |
| 2465 ''', |
| 2466 const Visit(VisitKind.ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
| 2467 arguments: '()', |
| 2468 type: 'Class', |
| 2469 selector: 'CallStructure(arity=0)')), |
| 2470 const Test( |
| 2471 ''' |
| 2472 class Class { |
| 2473 const Class() // Delibrate syntax error. |
| 2474 } |
| 2475 m() => const Class(); |
| 2476 ''', |
| 2477 const Visit(VisitKind.ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
| 2478 arguments: '()', |
| 2479 type: 'dynamic', |
| 2480 selector: 'CallStructure(arity=0)')), |
| 2481 const Test( |
| 2482 ''' |
| 2483 class Target {} |
| 2484 class Class { |
| 2485 const factory Class() = Target; |
| 2486 } |
| 2487 m() => const Class(); |
| 2488 ''', |
| 2489 const Visit(VisitKind.ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
| 2490 arguments: '()', |
| 2491 type: 'Class', |
| 2492 selector: 'CallStructure(arity=0)')), |
| 2493 /* Enable this when constness is handled consistently. |
| 2494 const Test( |
| 2495 ''' |
| 2496 class Target { |
| 2497 const Target(); |
| 2498 } |
| 2499 class Redirection { |
| 2500 factory Redirection() = Target; |
| 2501 } |
| 2502 class Class { |
| 2503 const factory Class() = Redirection; |
| 2504 } |
| 2505 m() => const Class(); |
| 2506 ''', |
| 2507 const Visit(VisitKind.ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
| 2508 arguments: '()', |
| 2509 type: 'Class', |
| 2510 selector: 'CallStructure(arity=0)')), |
| 2511 */ |
2461 ], | 2512 ], |
2462 }; | 2513 }; |
2463 | 2514 |
2464 const Map<String, List<Test>> DECL_TESTS = const { | 2515 const Map<String, List<Test>> DECL_TESTS = const { |
2465 'Function declarations': const [ | 2516 'Function declarations': const [ |
2466 const Test( | 2517 const Test( |
2467 ''' | 2518 ''' |
2468 m(a, b) {} | 2519 m(a, b) {} |
2469 ''', | 2520 ''', |
2470 const [ | 2521 const [ |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3317 } | 3368 } |
3318 | 3369 |
3319 String filename = 'lib$index.dart'; | 3370 String filename = 'lib$index.dart'; |
3320 testSource.writeln(test.code); | 3371 testSource.writeln(test.code); |
3321 sourceFiles[filename] = testSource.toString(); | 3372 sourceFiles[filename] = testSource.toString(); |
3322 mainSource.writeln("import '$filename';"); | 3373 mainSource.writeln("import '$filename';"); |
3323 testMap[filename] = test; | 3374 testMap[filename] = test; |
3324 index++; | 3375 index++; |
3325 }); | 3376 }); |
3326 }); | 3377 }); |
| 3378 |
3327 mainSource.writeln("main() {}"); | 3379 mainSource.writeln("main() {}"); |
3328 sourceFiles['main.dart'] = mainSource.toString(); | 3380 sourceFiles['main.dart'] = mainSource.toString(); |
3329 | 3381 |
3330 Compiler compiler = compilerFor(sourceFiles, | 3382 Compiler compiler = compilerFor(sourceFiles, |
3331 options: ['--analyze-all', '--analyze-only']); | 3383 options: ['--analyze-all', '--analyze-only']); |
3332 return compiler.run(Uri.parse('memory:main.dart')).then((_) { | 3384 return compiler.run(Uri.parse('memory:main.dart')).then((_) { |
3333 testMap.forEach((String filename, Test test) { | 3385 testMap.forEach((String filename, Test test) { |
3334 LibraryElement library = compiler.libraryLoader.lookupLibrary( | 3386 LibraryElement library = compiler.libraryLoader.lookupLibrary( |
3335 Uri.parse('memory:$filename')); | 3387 Uri.parse('memory:$filename')); |
3336 var expectedVisits = test.expectedVisits; | 3388 var expectedVisits = test.expectedVisits; |
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5582 CallStructure callStructure, | 5634 CallStructure callStructure, |
5583 arg) { | 5635 arg) { |
5584 visits.add(new Visit( | 5636 visits.add(new Visit( |
5585 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, | 5637 VisitKind.VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, |
5586 element: constructor, | 5638 element: constructor, |
5587 type: type, | 5639 type: type, |
5588 arguments: arguments, | 5640 arguments: arguments, |
5589 selector: callStructure)); | 5641 selector: callStructure)); |
5590 apply(arguments, arg); | 5642 apply(arguments, arg); |
5591 } | 5643 } |
| 5644 |
| 5645 @override |
| 5646 errorNonConstantConstructorInvoke( |
| 5647 NewExpression node, |
| 5648 Element element, |
| 5649 DartType type, |
| 5650 NodeList arguments, |
| 5651 CallStructure callStructure, |
| 5652 arg) { |
| 5653 visits.add(new Visit( |
| 5654 VisitKind.ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
| 5655 type: type, |
| 5656 arguments: arguments, |
| 5657 selector: callStructure)); |
| 5658 apply(arguments, arg); |
| 5659 } |
5592 } | 5660 } |
5593 | 5661 |
5594 class SemanticDeclarationTestVisitor extends SemanticTestVisitor { | 5662 class SemanticDeclarationTestVisitor extends SemanticTestVisitor { |
5595 | 5663 |
5596 SemanticDeclarationTestVisitor(TreeElements elements) : super(elements); | 5664 SemanticDeclarationTestVisitor(TreeElements elements) : super(elements); |
5597 | 5665 |
5598 @override | 5666 @override |
5599 errorUnresolvedSuperConstructorInvoke( | 5667 errorUnresolvedSuperConstructorInvoke( |
5600 Send node, | 5668 Send node, |
5601 Element element, | 5669 Element element, |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6410 VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, | 6478 VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, |
6411 | 6479 |
6412 VISIT_SUPER_CONSTRUCTOR_INVOKE, | 6480 VISIT_SUPER_CONSTRUCTOR_INVOKE, |
6413 VISIT_THIS_CONSTRUCTOR_INVOKE, | 6481 VISIT_THIS_CONSTRUCTOR_INVOKE, |
6414 VISIT_FIELD_INITIALIZER, | 6482 VISIT_FIELD_INITIALIZER, |
6415 | 6483 |
6416 VISIT_UNRESOLVED_CLASS_CONSTRUCTOR_INVOKE, | 6484 VISIT_UNRESOLVED_CLASS_CONSTRUCTOR_INVOKE, |
6417 VISIT_UNRESOLVED_CONSTRUCTOR_INVOKE, | 6485 VISIT_UNRESOLVED_CONSTRUCTOR_INVOKE, |
6418 VISIT_ABSTRACT_CLASS_CONSTRUCTOR_INVOKE, | 6486 VISIT_ABSTRACT_CLASS_CONSTRUCTOR_INVOKE, |
6419 VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, | 6487 VISIT_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE, |
| 6488 ERROR_NON_CONSTANT_CONSTRUCTOR_INVOKE, |
6420 | 6489 |
6421 VISIT_INSTANCE_GETTER_DECL, | 6490 VISIT_INSTANCE_GETTER_DECL, |
6422 VISIT_INSTANCE_SETTER_DECL, | 6491 VISIT_INSTANCE_SETTER_DECL, |
6423 VISIT_INSTANCE_METHOD_DECL, | 6492 VISIT_INSTANCE_METHOD_DECL, |
6424 VISIT_ABSTRACT_GETTER_DECL, | 6493 VISIT_ABSTRACT_GETTER_DECL, |
6425 VISIT_ABSTRACT_SETTER_DECL, | 6494 VISIT_ABSTRACT_SETTER_DECL, |
6426 VISIT_ABSTRACT_METHOD_DECL, | 6495 VISIT_ABSTRACT_METHOD_DECL, |
6427 VISIT_INSTANCE_FIELD_DECL, | 6496 VISIT_INSTANCE_FIELD_DECL, |
6428 | 6497 |
6429 VISIT_GENERATIVE_CONSTRUCTOR_DECL, | 6498 VISIT_GENERATIVE_CONSTRUCTOR_DECL, |
6430 VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_DECL, | 6499 VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_DECL, |
6431 VISIT_FACTORY_CONSTRUCTOR_DECL, | 6500 VISIT_FACTORY_CONSTRUCTOR_DECL, |
6432 VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_DECL, | 6501 VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_DECL, |
6433 | 6502 |
6434 VISIT_REQUIRED_PARAMETER_DECL, | 6503 VISIT_REQUIRED_PARAMETER_DECL, |
6435 VISIT_OPTIONAL_PARAMETER_DECL, | 6504 VISIT_OPTIONAL_PARAMETER_DECL, |
6436 VISIT_NAMED_PARAMETER_DECL, | 6505 VISIT_NAMED_PARAMETER_DECL, |
6437 VISIT_REQUIRED_INITIALIZING_FORMAL_DECL, | 6506 VISIT_REQUIRED_INITIALIZING_FORMAL_DECL, |
6438 VISIT_OPTIONAL_INITIALIZING_FORMAL_DECL, | 6507 VISIT_OPTIONAL_INITIALIZING_FORMAL_DECL, |
6439 VISIT_NAMED_INITIALIZING_FORMAL_DECL, | 6508 VISIT_NAMED_INITIALIZING_FORMAL_DECL, |
6440 | 6509 |
6441 ERROR_UNRESOLVED_POSTFIX, | 6510 ERROR_UNRESOLVED_POSTFIX, |
6442 | 6511 |
6443 // TODO(johnniwinther): Add tests for more error cases. | 6512 // TODO(johnniwinther): Add tests for more error cases. |
6444 } | 6513 } |
OLD | NEW |