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 analyzer.test.generated.compile_time_error_code_test; | 5 library analyzer.test.generated.compile_time_error_code_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2202 computeLibrarySourceErrors(source); | 2202 computeLibrarySourceErrors(source); |
2203 assertErrors(source, | 2203 assertErrors(source, |
2204 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); | 2204 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]); |
2205 verify([source]); | 2205 verify([source]); |
2206 } | 2206 } |
2207 | 2207 |
2208 void test_fieldInitializerFactoryConstructor() { | 2208 void test_fieldInitializerFactoryConstructor() { |
2209 Source source = addSource(r''' | 2209 Source source = addSource(r''' |
2210 class A { | 2210 class A { |
2211 int x; | 2211 int x; |
2212 factory A(this.x) {} | 2212 A.named() {} |
scheglov
2016/04/27 15:52:01
I think you could replace this with:
factory A(th
srawlins
2016/04/27 19:52:34
Great suggestion!
| |
2213 factory A(this.x) => new A.named(); | |
2213 }'''); | 2214 }'''); |
2214 computeLibrarySourceErrors(source); | 2215 computeLibrarySourceErrors(source); |
2215 assertErrors( | 2216 assertErrors( |
2216 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); | 2217 source, [CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR]); |
2217 verify([source]); | 2218 verify([source]); |
2218 } | 2219 } |
2219 | 2220 |
2220 void test_fieldInitializerOutsideConstructor() { | 2221 void test_fieldInitializerOutsideConstructor() { |
2221 // TODO(brianwilkerson) Fix the duplicate error messages. | 2222 // TODO(brianwilkerson) Fix the duplicate error messages. |
2222 Source source = addSource(r''' | 2223 Source source = addSource(r''' |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3194 }'''); | 3195 }'''); |
3195 computeLibrarySourceErrors(source); | 3196 computeLibrarySourceErrors(source); |
3196 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); | 3197 assertErrors(source, [CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]); |
3197 // no verify() call, "B" is not resolved | 3198 // no verify() call, "B" is not resolved |
3198 } | 3199 } |
3199 | 3200 |
3200 void test_invalidFactoryNameNotAClass_notClassName() { | 3201 void test_invalidFactoryNameNotAClass_notClassName() { |
3201 Source source = addSource(r''' | 3202 Source source = addSource(r''' |
3202 int B; | 3203 int B; |
3203 class A { | 3204 class A { |
3204 factory B() {} | 3205 A.named() {} |
3206 factory B() => new A.named(); | |
3205 }'''); | 3207 }'''); |
3206 computeLibrarySourceErrors(source); | 3208 computeLibrarySourceErrors(source); |
3207 assertErrors( | 3209 assertErrors( |
3208 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); | 3210 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); |
3209 verify([source]); | 3211 verify([source]); |
3210 } | 3212 } |
3211 | 3213 |
3212 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { | 3214 void test_invalidFactoryNameNotAClass_notEnclosingClassName() { |
3213 Source source = addSource(r''' | 3215 Source source = addSource(r''' |
3214 class A { | 3216 class A { |
3215 factory B() {} | 3217 A.named() {} |
3218 factory B() => new A.named(); | |
3216 }'''); | 3219 }'''); |
3217 computeLibrarySourceErrors(source); | 3220 computeLibrarySourceErrors(source); |
3218 assertErrors( | 3221 assertErrors( |
3219 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); | 3222 source, [CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]); |
3220 // no verify() call, "B" is not resolved | 3223 // no verify() call, "B" is not resolved |
3221 } | 3224 } |
3222 | 3225 |
3223 void test_invalidModifierOnConstructor_async() { | 3226 void test_invalidModifierOnConstructor_async() { |
3224 Source source = addSource(r''' | 3227 Source source = addSource(r''' |
3225 class A { | 3228 class A { |
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4729 }''' | 4732 }''' |
4730 ], <ErrorCode>[ | 4733 ], <ErrorCode>[ |
4731 CompileTimeErrorCode | 4734 CompileTimeErrorCode |
4732 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY | 4735 .NON_CONSTANT_VALUE_IN_INITIALIZER_FROM_DEFERRED_LIBRARY |
4733 ]); | 4736 ]); |
4734 } | 4737 } |
4735 | 4738 |
4736 void test_nonGenerativeConstructor_explicit() { | 4739 void test_nonGenerativeConstructor_explicit() { |
4737 Source source = addSource(r''' | 4740 Source source = addSource(r''' |
4738 class A { | 4741 class A { |
4739 factory A.named() {} | 4742 A.named2() {} |
4743 factory A.named() => new A.named2(); | |
4740 } | 4744 } |
4741 class B extends A { | 4745 class B extends A { |
4742 B() : super.named(); | 4746 B() : super.named(); |
4743 }'''); | 4747 }'''); |
4744 computeLibrarySourceErrors(source); | 4748 computeLibrarySourceErrors(source); |
4745 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4749 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4746 verify([source]); | 4750 verify([source]); |
4747 } | 4751 } |
4748 | 4752 |
4749 void test_nonGenerativeConstructor_implicit() { | 4753 void test_nonGenerativeConstructor_implicit() { |
4750 Source source = addSource(r''' | 4754 Source source = addSource(r''' |
4751 class A { | 4755 class A { |
4752 factory A() {} | 4756 A.named() {} |
4757 factory A() => new A.named(); | |
4753 } | 4758 } |
4754 class B extends A { | 4759 class B extends A { |
4755 B(); | 4760 B(); |
4756 }'''); | 4761 }'''); |
4757 computeLibrarySourceErrors(source); | 4762 computeLibrarySourceErrors(source); |
4758 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4763 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4759 verify([source]); | 4764 verify([source]); |
4760 } | 4765 } |
4761 | 4766 |
4762 void test_nonGenerativeConstructor_implicit2() { | 4767 void test_nonGenerativeConstructor_implicit2() { |
4763 Source source = addSource(r''' | 4768 Source source = addSource(r''' |
4764 class A { | 4769 class A { |
4765 factory A() {} | 4770 A.named() {} |
4771 factory A() => new A.named(); | |
4766 } | 4772 } |
4767 class B extends A { | 4773 class B extends A { |
4768 }'''); | 4774 }'''); |
4769 computeLibrarySourceErrors(source); | 4775 computeLibrarySourceErrors(source); |
4770 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); | 4776 assertErrors(source, [CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR]); |
4771 verify([source]); | 4777 verify([source]); |
4772 } | 4778 } |
4773 | 4779 |
4774 void test_notEnoughRequiredArguments_const() { | 4780 void test_notEnoughRequiredArguments_const() { |
4775 Source source = addSource(r''' | 4781 Source source = addSource(r''' |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5751 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5757 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5752 // no verify(), 'super.m' is not resolved | 5758 // no verify(), 'super.m' is not resolved |
5753 } | 5759 } |
5754 | 5760 |
5755 void test_superInInvalidContext_factoryConstructor() { | 5761 void test_superInInvalidContext_factoryConstructor() { |
5756 Source source = addSource(r''' | 5762 Source source = addSource(r''' |
5757 class A { | 5763 class A { |
5758 m() {} | 5764 m() {} |
5759 } | 5765 } |
5760 class B extends A { | 5766 class B extends A { |
5767 B.named() {} | |
5761 factory B() { | 5768 factory B() { |
5762 super.m(); | 5769 super.m(); |
5770 return new B.named(); | |
5763 } | 5771 } |
5764 }'''); | 5772 }'''); |
5765 computeLibrarySourceErrors(source); | 5773 computeLibrarySourceErrors(source); |
5766 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); | 5774 assertErrors(source, [CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]); |
5767 // no verify(), 'super.m' is not resolved | 5775 // no verify(), 'super.m' is not resolved |
5768 } | 5776 } |
5769 | 5777 |
5770 void test_superInInvalidContext_instanceVariableInitializer() { | 5778 void test_superInInvalidContext_instanceVariableInitializer() { |
5771 Source source = addSource(r''' | 5779 Source source = addSource(r''' |
5772 class A { | 5780 class A { |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6337 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 6345 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
6338 verify([source]); | 6346 verify([source]); |
6339 reset(); | 6347 reset(); |
6340 } | 6348 } |
6341 | 6349 |
6342 void _check_wrongNumberOfParametersForOperator1(String name) { | 6350 void _check_wrongNumberOfParametersForOperator1(String name) { |
6343 _check_wrongNumberOfParametersForOperator(name, ""); | 6351 _check_wrongNumberOfParametersForOperator(name, ""); |
6344 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 6352 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
6345 } | 6353 } |
6346 } | 6354 } |
OLD | NEW |