diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index 0e9ad7b77e0..3b4ccac8e45 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -59,6 +59,7 @@ const List errorCodeValues = const [ CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_NON_PARAMETER, CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT, + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_PREFIX_NAME, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart index 8171fa6ab13..c31595032fe 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -248,6 +248,20 @@ class CompileTimeErrorCode extends ErrorCode { "The await expression can only be used in an asynchronous function.", "Try marking the function body with either 'async' or 'async*'."); + /** + * 16.33 Identifier Reference: It is a compile-time error if a built-in + * identifier is used as the declared name of a prefix, class, type parameter + * or type alias. + * + * Parameters: + * 0: the built-in identifier that is being used + */ + static const CompileTimeErrorCode BUILT_IN_IDENTIFIER_AS_PREFIX_NAME = + const CompileTimeErrorCode( + 'BUILT_IN_IDENTIFIER_AS_PREFIX_NAME', + "The built-in identifier '{0}' can't be used as a prefix name.", + "Try choosing a different name for the prefix."); + /** * 12.30 Identifier Reference: It is a compile-time error to use a built-in * identifier other than dynamic as a type annotation. @@ -262,9 +276,9 @@ class CompileTimeErrorCode extends ErrorCode { "Try correcting the name to match an existing type."); /** - * 12.30 Identifier Reference: It is a compile-time error if a built-in - * identifier is used as the declared name of a class, type parameter or type - * alias. + * 16.33 Identifier Reference: It is a compile-time error if a built-in + * identifier is used as the declared name of a prefix, class, type parameter + * or type alias. * * Parameters: * 0: the built-in identifier that is being used @@ -276,9 +290,9 @@ class CompileTimeErrorCode extends ErrorCode { "Try choosing a different name for the type."); /** - * 12.30 Identifier Reference: It is a compile-time error if a built-in - * identifier is used as the declared name of a class, type parameter or type - * alias. + * 16.33 Identifier Reference: It is a compile-time error if a built-in + * identifier is used as the declared name of a prefix, class, type parameter + * or type alias. * * Parameters: * 0: the built-in identifier that is being used @@ -290,9 +304,9 @@ class CompileTimeErrorCode extends ErrorCode { "Try choosing a different name for the typedef."); /** - * 12.30 Identifier Reference: It is a compile-time error if a built-in - * identifier is used as the declared name of a class, type parameter or type - * alias. + * 16.33 Identifier Reference: It is a compile-time error if a built-in + * identifier is used as the declared name of a prefix, class, type parameter + * or type alias. * * Parameters: * 0: the built-in identifier that is being used diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index c9bcf4350f7..1fa5eae09db 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -900,6 +900,10 @@ class ErrorVerifier extends RecursiveAstVisitor { @override Object visitImportDirective(ImportDirective node) { ImportElement importElement = node.element; + if (node.prefix != null) { + _checkForBuiltInIdentifierAsName( + node.prefix, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_PREFIX_NAME); + } if (importElement != null) { _checkForImportDuplicateLibraryName(node, importElement); _checkForImportInternalLibrary(node, importElement); diff --git a/pkg/analyzer/test/generated/compile_time_error_code_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_test.dart index 3c95c9da539..a8b21c98948 100644 --- a/pkg/analyzer/test/generated/compile_time_error_code_test.dart +++ b/pkg/analyzer/test/generated/compile_time_error_code_test.dart @@ -624,6 +624,16 @@ class as = A with B;'''); verify([source]); } + test_builtInIdentifierAsPrefixName() async { + Source source = addSource("import 'dart:async' as abstract;"); + await computeAnalysisResult(source); + assertErrors(source, [ + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_PREFIX_NAME, + HintCode.UNUSED_IMPORT + ]); + verify([source]); + } + test_builtInIdentifierAsType_formalParameter_field() async { Source source = addSource(r''' class A { diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart index 21568ccad12..f9c5a45f0b5 100644 --- a/pkg/analyzer/test/generated/non_error_resolver_test.dart +++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart @@ -2195,17 +2195,6 @@ class B { verify([source]); } - test_implicitThisReferenceInInitializer_importPrefix() async { - Source source = addSource(r''' -import 'dart:async' as abstract; -class A { - var v = new abstract.Completer(); -}'''); - await computeAnalysisResult(source); - assertNoErrors(source); - verify([source]); - } - test_implicitThisReferenceInInitializer_prefixedIdentifier() async { Source source = addSource(r''' class A { diff --git a/tests/co19/co19-analyzer2.status b/tests/co19/co19-analyzer2.status index 58406e63d9b..b6aac2262f4 100644 --- a/tests/co19/co19-analyzer2.status +++ b/tests/co19/co19-analyzer2.status @@ -26,22 +26,6 @@ Language/Expressions/Function_Invocation/Unqualified_Invocation/instance_context Language/Expressions/Function_Invocation/Unqualified_Invocation/instance_context_invocation_t04: MissingCompileTimeError # Please triage this failure. Language/Expressions/Function_Invocation/Unqualified_Invocation/invocation_t17: MissingCompileTimeError # Please triage this failure Language/Expressions/Function_Invocation/Unqualified_Invocation/invocation_t18: MissingCompileTimeError # Please triage this failure -Language/Expressions/Identifier_Reference/built_in_identifier_t53: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t54: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t55: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t56: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t57: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t58: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t59: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t60: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t61: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t62: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t63: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t64: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t65: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t66: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t67: MissingCompileTimeError # Issue 25733 -Language/Expressions/Identifier_Reference/built_in_identifier_t68: MissingCompileTimeError # Issue 25733 Language/Expressions/Identifier_Reference/built_in_not_dynamic_t17: MissingCompileTimeError # Please triage this failure. Language/Expressions/Identifier_Reference/built_in_not_dynamic_t18: MissingCompileTimeError # Please triage this failure. Language/Expressions/Identifier_Reference/built_in_not_dynamic_t19: MissingCompileTimeError # Please triage this failure.