| 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/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'; |
| 11 import 'package:unittest/unittest.dart' as _ut; | 11 import 'package:unittest/unittest.dart' as _ut; |
| 12 | 12 |
| 13 import '../reflective_tests.dart'; | 13 import '../reflective_tests.dart'; |
| 14 import 'resolver_test.dart'; | 14 import 'resolver_test.dart'; |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 _ut.groupSep = ' | '; | 17 _ut.groupSep = ' | '; |
| 18 runReflectiveTests(CompileTimeErrorCodeTest); | 18 runReflectiveTests(CompileTimeErrorCodeTest); |
| 19 } | 19 } |
| 20 | 20 |
| 21 @reflectiveTest | 21 @reflectiveTest |
| 22 class CompileTimeErrorCodeTest extends ResolverTestCase { | 22 class CompileTimeErrorCodeTest extends ResolverTestCase { |
| 23 /** | |
| 24 * Computes errors for the given [librarySource]. | |
| 25 * This assumes that the given [librarySource] and its parts have already | |
| 26 * been added to the content provider using the method [addNamedSource]. | |
| 27 */ | |
| 28 void computeLibrarySourceErrors(Source librarySource) { | |
| 29 analysisContext.computeErrors(librarySource); | |
| 30 } | |
| 31 | |
| 32 void fail_awaitInWrongContext_sync() { | 23 void fail_awaitInWrongContext_sync() { |
| 33 // This test requires better error recovery than we currently have. In | 24 // This test requires better error recovery than we currently have. In |
| 34 // particular, we need to be able to distinguish between an await expression | 25 // particular, we need to be able to distinguish between an await expression |
| 35 // in the wrong context, and the use of 'await' as an identifier. | 26 // in the wrong context, and the use of 'await' as an identifier. |
| 36 Source source = addSource(r''' | 27 Source source = addSource(r''' |
| 37 f(x) { | 28 f(x) { |
| 38 return await x; | 29 return await x; |
| 39 }'''); | 30 }'''); |
| 40 computeLibrarySourceErrors(source); | 31 computeLibrarySourceErrors(source); |
| 41 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); | 32 assertErrors(source, [CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT]); |
| (...skipping 4668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4710 addNamedSource('/lib.dart', ''' | 4701 addNamedSource('/lib.dart', ''' |
| 4711 library lib; | 4702 library lib; |
| 4712 g() {} | 4703 g() {} |
| 4713 '''); | 4704 '''); |
| 4714 Source source = addSource(''' | 4705 Source source = addSource(''' |
| 4715 import 'lib.dart' as p; | 4706 import 'lib.dart' as p; |
| 4716 f() { | 4707 f() { |
| 4717 p?.g(); | 4708 p?.g(); |
| 4718 } | 4709 } |
| 4719 '''); | 4710 '''); |
| 4720 resolve(source); | 4711 computeLibrarySourceErrors(source); |
| 4721 assertErrors( | 4712 assertErrors( |
| 4722 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4713 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4723 verify([source]); | 4714 verify([source]); |
| 4724 } | 4715 } |
| 4725 | 4716 |
| 4726 void test_prefix_conditionalPropertyAccess_call_loadLibrary() { | 4717 void test_prefix_conditionalPropertyAccess_call_loadLibrary() { |
| 4727 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4718 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4728 options.enableNullAwareOperators = true; | 4719 options.enableNullAwareOperators = true; |
| 4729 resetWithOptions(options); | 4720 resetWithOptions(options); |
| 4730 addNamedSource('/lib.dart', ''' | 4721 addNamedSource('/lib.dart', ''' |
| 4731 library lib; | 4722 library lib; |
| 4732 '''); | 4723 '''); |
| 4733 Source source = addSource(''' | 4724 Source source = addSource(''' |
| 4734 import 'lib.dart' deferred as p; | 4725 import 'lib.dart' deferred as p; |
| 4735 f() { | 4726 f() { |
| 4736 p?.loadLibrary(); | 4727 p?.loadLibrary(); |
| 4737 } | 4728 } |
| 4738 '''); | 4729 '''); |
| 4739 resolve(source); | 4730 computeLibrarySourceErrors(source); |
| 4740 assertErrors( | 4731 assertErrors( |
| 4741 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4732 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4742 verify([source]); | 4733 verify([source]); |
| 4743 } | 4734 } |
| 4744 | 4735 |
| 4745 void test_prefix_conditionalPropertyAccess_get() { | 4736 void test_prefix_conditionalPropertyAccess_get() { |
| 4746 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4737 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4747 options.enableNullAwareOperators = true; | 4738 options.enableNullAwareOperators = true; |
| 4748 resetWithOptions(options); | 4739 resetWithOptions(options); |
| 4749 addNamedSource('/lib.dart', ''' | 4740 addNamedSource('/lib.dart', ''' |
| 4750 library lib; | 4741 library lib; |
| 4751 var x; | 4742 var x; |
| 4752 '''); | 4743 '''); |
| 4753 Source source = addSource(''' | 4744 Source source = addSource(''' |
| 4754 import 'lib.dart' as p; | 4745 import 'lib.dart' as p; |
| 4755 f() { | 4746 f() { |
| 4756 return p?.x; | 4747 return p?.x; |
| 4757 } | 4748 } |
| 4758 '''); | 4749 '''); |
| 4759 resolve(source); | 4750 computeLibrarySourceErrors(source); |
| 4760 assertErrors( | 4751 assertErrors( |
| 4761 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4752 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4762 verify([source]); | 4753 verify([source]); |
| 4763 } | 4754 } |
| 4764 | 4755 |
| 4765 void test_prefix_conditionalPropertyAccess_get_loadLibrary() { | 4756 void test_prefix_conditionalPropertyAccess_get_loadLibrary() { |
| 4766 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4757 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4767 options.enableNullAwareOperators = true; | 4758 options.enableNullAwareOperators = true; |
| 4768 resetWithOptions(options); | 4759 resetWithOptions(options); |
| 4769 addNamedSource('/lib.dart', ''' | 4760 addNamedSource('/lib.dart', ''' |
| 4770 library lib; | 4761 library lib; |
| 4771 '''); | 4762 '''); |
| 4772 Source source = addSource(''' | 4763 Source source = addSource(''' |
| 4773 import 'lib.dart' deferred as p; | 4764 import 'lib.dart' deferred as p; |
| 4774 f() { | 4765 f() { |
| 4775 return p?.loadLibrary; | 4766 return p?.loadLibrary; |
| 4776 } | 4767 } |
| 4777 '''); | 4768 '''); |
| 4778 resolve(source); | 4769 computeLibrarySourceErrors(source); |
| 4779 assertErrors( | 4770 assertErrors( |
| 4780 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4771 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4781 verify([source]); | 4772 verify([source]); |
| 4782 } | 4773 } |
| 4783 | 4774 |
| 4784 void test_prefix_conditionalPropertyAccess_set() { | 4775 void test_prefix_conditionalPropertyAccess_set() { |
| 4785 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4776 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4786 options.enableNullAwareOperators = true; | 4777 options.enableNullAwareOperators = true; |
| 4787 resetWithOptions(options); | 4778 resetWithOptions(options); |
| 4788 addNamedSource('/lib.dart', ''' | 4779 addNamedSource('/lib.dart', ''' |
| 4789 library lib; | 4780 library lib; |
| 4790 var x; | 4781 var x; |
| 4791 '''); | 4782 '''); |
| 4792 Source source = addSource(''' | 4783 Source source = addSource(''' |
| 4793 import 'lib.dart' as p; | 4784 import 'lib.dart' as p; |
| 4794 f() { | 4785 f() { |
| 4795 p?.x = null; | 4786 p?.x = null; |
| 4796 } | 4787 } |
| 4797 '''); | 4788 '''); |
| 4798 resolve(source); | 4789 computeLibrarySourceErrors(source); |
| 4799 assertErrors( | 4790 assertErrors( |
| 4800 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4791 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4801 verify([source]); | 4792 verify([source]); |
| 4802 } | 4793 } |
| 4803 | 4794 |
| 4804 void test_prefix_conditionalPropertyAccess_set_loadLibrary() { | 4795 void test_prefix_conditionalPropertyAccess_set_loadLibrary() { |
| 4805 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4796 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4806 options.enableNullAwareOperators = true; | 4797 options.enableNullAwareOperators = true; |
| 4807 resetWithOptions(options); | 4798 resetWithOptions(options); |
| 4808 addNamedSource('/lib.dart', ''' | 4799 addNamedSource('/lib.dart', ''' |
| 4809 library lib; | 4800 library lib; |
| 4810 '''); | 4801 '''); |
| 4811 Source source = addSource(''' | 4802 Source source = addSource(''' |
| 4812 import 'lib.dart' deferred as p; | 4803 import 'lib.dart' deferred as p; |
| 4813 f() { | 4804 f() { |
| 4814 p?.loadLibrary = null; | 4805 p?.loadLibrary = null; |
| 4815 } | 4806 } |
| 4816 '''); | 4807 '''); |
| 4817 resolve(source); | 4808 computeLibrarySourceErrors(source); |
| 4818 assertErrors( | 4809 assertErrors( |
| 4819 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4810 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4820 verify([source]); | 4811 verify([source]); |
| 4821 } | 4812 } |
| 4822 | 4813 |
| 4823 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { | 4814 void test_prefixCollidesWithTopLevelMembers_functionTypeAlias() { |
| 4824 addNamedSource("/lib.dart", r''' | 4815 addNamedSource("/lib.dart", r''' |
| 4825 library lib; | 4816 library lib; |
| 4826 class A{}'''); | 4817 class A{}'''); |
| 4827 Source source = addSource(r''' | 4818 Source source = addSource(r''' |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4877 } | 4868 } |
| 4878 | 4869 |
| 4879 void test_prefixNotFollowedByDot() { | 4870 void test_prefixNotFollowedByDot() { |
| 4880 addNamedSource('/lib.dart', 'library lib;'); | 4871 addNamedSource('/lib.dart', 'library lib;'); |
| 4881 Source source = addSource(''' | 4872 Source source = addSource(''' |
| 4882 import 'lib.dart' as p; | 4873 import 'lib.dart' as p; |
| 4883 f() { | 4874 f() { |
| 4884 return p; | 4875 return p; |
| 4885 } | 4876 } |
| 4886 '''); | 4877 '''); |
| 4887 resolve(source); | 4878 computeLibrarySourceErrors(source); |
| 4888 assertErrors( | 4879 assertErrors( |
| 4889 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4880 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4890 verify([source]); | 4881 verify([source]); |
| 4891 } | 4882 } |
| 4892 | 4883 |
| 4893 void test_prefixNotFollowedByDot_compoundAssignment() { | 4884 void test_prefixNotFollowedByDot_compoundAssignment() { |
| 4894 addNamedSource('/lib.dart', 'library lib;'); | 4885 addNamedSource('/lib.dart', 'library lib;'); |
| 4895 Source source = addSource(''' | 4886 Source source = addSource(''' |
| 4896 import 'lib.dart' as p; | 4887 import 'lib.dart' as p; |
| 4897 f() { | 4888 f() { |
| 4898 p += 1; | 4889 p += 1; |
| 4899 } | 4890 } |
| 4900 '''); | 4891 '''); |
| 4901 resolve(source); | 4892 computeLibrarySourceErrors(source); |
| 4902 assertErrors( | 4893 assertErrors( |
| 4903 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4894 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4904 verify([source]); | 4895 verify([source]); |
| 4905 } | 4896 } |
| 4906 | 4897 |
| 4907 void test_prefixNotFollowedByDot_conditionalMethodInvocation() { | 4898 void test_prefixNotFollowedByDot_conditionalMethodInvocation() { |
| 4908 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 4899 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4909 options.enableNullAwareOperators = true; | 4900 options.enableNullAwareOperators = true; |
| 4910 resetWithOptions(options); | 4901 resetWithOptions(options); |
| 4911 addNamedSource('/lib.dart', ''' | 4902 addNamedSource('/lib.dart', ''' |
| 4912 library lib; | 4903 library lib; |
| 4913 g() {} | 4904 g() {} |
| 4914 '''); | 4905 '''); |
| 4915 Source source = addSource(''' | 4906 Source source = addSource(''' |
| 4916 import 'lib.dart' as p; | 4907 import 'lib.dart' as p; |
| 4917 f() { | 4908 f() { |
| 4918 p?.g(); | 4909 p?.g(); |
| 4919 } | 4910 } |
| 4920 '''); | 4911 '''); |
| 4921 resolve(source); | 4912 computeLibrarySourceErrors(source); |
| 4922 assertErrors( | 4913 assertErrors( |
| 4923 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); | 4914 source, [CompileTimeErrorCode.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT]); |
| 4924 verify([source]); | 4915 verify([source]); |
| 4925 } | 4916 } |
| 4926 | 4917 |
| 4927 void test_privateOptionalParameter() { | 4918 void test_privateOptionalParameter() { |
| 4928 Source source = addSource("f({var _p}) {}"); | 4919 Source source = addSource("f({var _p}) {}"); |
| 4929 computeLibrarySourceErrors(source); | 4920 computeLibrarySourceErrors(source); |
| 4930 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); | 4921 assertErrors(source, [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]); |
| 4931 verify([source]); | 4922 verify([source]); |
| (...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6042 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 6033 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 6043 verify([source]); | 6034 verify([source]); |
| 6044 reset(); | 6035 reset(); |
| 6045 } | 6036 } |
| 6046 | 6037 |
| 6047 void _check_wrongNumberOfParametersForOperator1(String name) { | 6038 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 6048 _check_wrongNumberOfParametersForOperator(name, ""); | 6039 _check_wrongNumberOfParametersForOperator(name, ""); |
| 6049 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 6040 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 6050 } | 6041 } |
| 6051 } | 6042 } |
| OLD | NEW |