Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.compile_time_error_code_test; | 5 library engine.compile_time_error_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 8 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart' as _ut; | 10 import 'package:unittest/unittest.dart' as _ut; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 128 |
| 129 void fail_objectCannotExtendAnotherClass() { | 129 void fail_objectCannotExtendAnotherClass() { |
| 130 Source source = addSource(r''' | 130 Source source = addSource(r''' |
| 131 '''); | 131 '''); |
| 132 resolve(source); | 132 resolve(source); |
| 133 assertErrors( | 133 assertErrors( |
| 134 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]); | 134 source, [CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]); |
| 135 verify([source]); | 135 verify([source]); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void fail_recursiveCompileTimeConstant() { | |
| 139 Source source = addSource(r''' | |
| 140 class A { | |
| 141 const A(); | |
| 142 final m = const A(); | |
| 143 }'''); | |
| 144 resolve(source); | |
| 145 assertErrors( | |
| 146 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | |
| 147 verify([source]); | |
| 148 } | |
| 149 | |
| 150 void fail_recursiveCompileTimeConstant_cycle() { | |
| 151 Source source = addSource(r''' | |
| 152 const x = y + 1; | |
| 153 const y = x + 1;'''); | |
| 154 resolve(source); | |
| 155 assertErrors( | |
| 156 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | |
| 157 verify([source]); | |
| 158 } | |
| 159 | |
| 160 void fail_superInitializerInObject() { | 138 void fail_superInitializerInObject() { |
| 161 Source source = addSource(r''' | 139 Source source = addSource(r''' |
| 162 '''); | 140 '''); |
| 163 resolve(source); | 141 resolve(source); |
| 164 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); | 142 assertErrors(source, [CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]); |
| 165 verify([source]); | 143 verify([source]); |
| 166 } | 144 } |
| 167 | 145 |
| 168 void fail_yieldEachInNonGenerator_async() { | 146 void fail_yieldEachInNonGenerator_async() { |
| 169 // TODO(brianwilkerson) We are currently parsing the yield statement as a | 147 // TODO(brianwilkerson) We are currently parsing the yield statement as a |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 void test_constConstructorWithFieldInitializedByNonConst() { | 828 void test_constConstructorWithFieldInitializedByNonConst() { |
| 851 Source source = addSource(r''' | 829 Source source = addSource(r''' |
| 852 class A { | 830 class A { |
| 853 final int i = f(); | 831 final int i = f(); |
| 854 const A(); | 832 const A(); |
| 855 } | 833 } |
| 856 int f() { | 834 int f() { |
| 857 return 3; | 835 return 3; |
| 858 }'''); | 836 }'''); |
| 859 resolve(source); | 837 resolve(source); |
| 838 // TODO(paulberry): the error CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE is | |
| 839 // redundant and ought to be suppressed. | |
| 860 assertErrors(source, [ | 840 assertErrors(source, [ |
| 861 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST | 841 CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST , |
| 842 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | |
| 862 ]); | 843 ]); |
| 863 verify([source]); | 844 verify([source]); |
| 864 } | 845 } |
| 865 | 846 |
| 866 void test_constConstructorWithFieldInitializedByNonConst_static() { | 847 void test_constConstructorWithFieldInitializedByNonConst_static() { |
| 867 Source source = addSource(r''' | 848 Source source = addSource(r''' |
| 868 class A { | 849 class A { |
| 869 static final int i = f(); | 850 static final int i = f(); |
| 870 const A(); | 851 const A(); |
| 871 } | 852 } |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 verify([source]); | 1342 verify([source]); |
| 1362 } | 1343 } |
| 1363 | 1344 |
| 1364 void test_constWithNonConstantArgument_instanceCreation() { | 1345 void test_constWithNonConstantArgument_instanceCreation() { |
| 1365 Source source = addSource(r''' | 1346 Source source = addSource(r''' |
| 1366 class A { | 1347 class A { |
| 1367 const A(a); | 1348 const A(a); |
| 1368 } | 1349 } |
| 1369 f(p) { return const A(p); }'''); | 1350 f(p) { return const A(p); }'''); |
| 1370 resolve(source); | 1351 resolve(source); |
| 1371 assertErrors( | 1352 assertErrors(source, [ |
| 1372 source, [CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]); | 1353 CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT, |
| 1354 CompileTimeErrorCode.INVALID_CONSTANT | |
|
Brian Wilkerson
2015/05/05 21:25:24
This new error (both here and below) also seems to
Paul Berry
2015/05/05 21:46:31
Agreed. I've added TODO comments.
| |
| 1355 ]); | |
| 1373 verify([source]); | 1356 verify([source]); |
| 1374 } | 1357 } |
| 1375 | 1358 |
| 1376 void test_constWithNonType() { | 1359 void test_constWithNonType() { |
| 1377 Source source = addSource(r''' | 1360 Source source = addSource(r''' |
| 1378 int A; | 1361 int A; |
| 1379 f() { | 1362 f() { |
| 1380 return const A(); | 1363 return const A(); |
| 1381 }'''); | 1364 }'''); |
| 1382 resolve(source); | 1365 resolve(source); |
| (...skipping 2990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4373 Source source = addSource(r''' | 4356 Source source = addSource(r''' |
| 4374 class A { | 4357 class A { |
| 4375 A(); | 4358 A(); |
| 4376 } | 4359 } |
| 4377 class B { | 4360 class B { |
| 4378 const B() : a = new A(); | 4361 const B() : a = new A(); |
| 4379 final a; | 4362 final a; |
| 4380 } | 4363 } |
| 4381 var b = const B();'''); | 4364 var b = const B();'''); |
| 4382 resolve(source); | 4365 resolve(source); |
| 4383 assertErrors( | 4366 assertErrors(source, [ |
| 4384 source, [CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]); | 4367 CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER, |
| 4368 CompileTimeErrorCode.INVALID_CONSTANT | |
| 4369 ]); | |
| 4385 verify([source]); | 4370 verify([source]); |
| 4386 } | 4371 } |
| 4387 | 4372 |
| 4388 void test_nonConstValueInInitializer_redirecting() { | 4373 void test_nonConstValueInInitializer_redirecting() { |
| 4389 Source source = addSource(r''' | 4374 Source source = addSource(r''' |
| 4390 class A { | 4375 class A { |
| 4391 static var C; | 4376 static var C; |
| 4392 const A.named(p); | 4377 const A.named(p); |
| 4393 const A() : this.named(C); | 4378 const A() : this.named(C); |
| 4394 }'''); | 4379 }'''); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4651 verify([source]); | 4636 verify([source]); |
| 4652 } | 4637 } |
| 4653 | 4638 |
| 4654 void test_privateOptionalParameter_withDefaultValue() { | 4639 void test_privateOptionalParameter_withDefaultValue() { |
| 4655 Source source = addSource("f({_p : 0}) {}"); | 4640 Source source = addSource("f({_p : 0}) {}"); |
| 4656 resolve(source); | 4641 resolve(source); |
| 4657 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); | 4642 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
| 4658 verify([source]); | 4643 verify([source]); |
| 4659 } | 4644 } |
| 4660 | 4645 |
| 4646 void test_recursiveCompileTimeConstant() { | |
| 4647 Source source = addSource(r''' | |
| 4648 class A { | |
| 4649 const A(); | |
| 4650 final m = const A(); | |
| 4651 }'''); | |
| 4652 resolve(source); | |
| 4653 assertErrors( | |
| 4654 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | |
| 4655 verify([source]); | |
| 4656 } | |
| 4657 | |
| 4658 void test_recursiveCompileTimeConstant_cycle() { | |
| 4659 Source source = addSource(r''' | |
| 4660 const x = y + 1; | |
| 4661 const y = x + 1;'''); | |
| 4662 resolve(source); | |
| 4663 assertErrors(source, [ | |
| 4664 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, | |
| 4665 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT | |
| 4666 ]); | |
| 4667 verify([source]); | |
| 4668 } | |
| 4669 | |
| 4670 void test_recursiveCompileTimeConstant_initializer_after_toplevel_var() { | |
| 4671 Source source = addSource(''' | |
| 4672 const y = const C(); | |
| 4673 class C { | |
| 4674 const C() : x = y; | |
| 4675 final x; | |
| 4676 } | |
| 4677 '''); | |
| 4678 resolve(source); | |
| 4679 assertErrors( | |
| 4680 source, [CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]); | |
| 4681 verify([source]); | |
| 4682 } | |
| 4683 | |
| 4661 void test_recursiveConstructorRedirect() { | 4684 void test_recursiveConstructorRedirect() { |
| 4662 Source source = addSource(r''' | 4685 Source source = addSource(r''' |
| 4663 class A { | 4686 class A { |
| 4664 A.a() : this.b(); | 4687 A.a() : this.b(); |
| 4665 A.b() : this.a(); | 4688 A.b() : this.a(); |
| 4666 }'''); | 4689 }'''); |
| 4667 resolve(source); | 4690 resolve(source); |
| 4668 assertErrors(source, [ | 4691 assertErrors(source, [ |
| 4669 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, | 4692 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT, |
| 4670 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT | 4693 CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT |
| (...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5703 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5726 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 5704 verify([source]); | 5727 verify([source]); |
| 5705 reset(); | 5728 reset(); |
| 5706 } | 5729 } |
| 5707 | 5730 |
| 5708 void _check_wrongNumberOfParametersForOperator1(String name) { | 5731 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 5709 _check_wrongNumberOfParametersForOperator(name, ""); | 5732 _check_wrongNumberOfParametersForOperator(name, ""); |
| 5710 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5733 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 5711 } | 5734 } |
| 5712 } | 5735 } |
| OLD | NEW |