From 28e64680289467db8cde9c23f00d559214685758 Mon Sep 17 00:00:00 2001 From: lfkdsk Date: Sat, 17 Apr 2021 22:43:57 +0800 Subject: [PATCH 1/4] Cause CompileTimeError in analyzer when use 'Function' as a type: 1. cause CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION when declare class named 'Function'. 2. cause CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION when declare mixin named 'Function'. 3. cause CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION when declare extension named 'Function'. 4. cause CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER when type parameters contain parma named 'Function'. --- pkg/analyzer/lib/error/error.dart | 5 +- pkg/analyzer/lib/src/error/codes.dart | 28 +++++++++ .../lib/src/generated/error_verifier.dart | 60 +++++++++++++++++-- .../deprecated_extends_function_test.dart | 3 +- ...ated_function_as_type_identifier_test.dart | 37 ++++++++++++ ...cated_function_class_declaration_test.dart | 14 ++++- .../deprecated_mixin_function_test.dart | 13 +++- .../test/src/diagnostics/test_all.dart | 3 + 8 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index 0134b77d0d35..ab96a3e8789e 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -461,6 +461,10 @@ const List errorCodeValues = [ CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR, CompileTimeErrorCode.YIELD_IN_NON_GENERATOR, CompileTimeErrorCode.YIELD_OF_INVALID_TYPE, + CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, + CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, + CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, + CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, FfiCode.ANNOTATION_ON_POINTER_FIELD, FfiCode.EMPTY_STRUCT, FfiCode.EXTRA_ANNOTATION_ON_STRUCT_FIELD, @@ -497,7 +501,6 @@ const List errorCodeValues = [ HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH, HintCode.DEAD_CODE_ON_CATCH_SUBTYPE, HintCode.DEPRECATED_EXTENDS_FUNCTION, - HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, HintCode.DEPRECATED_MEMBER_USE, HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart index 9900a5e19a43..c6e770b23236 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -13721,6 +13721,34 @@ class CompileTimeErrorCode extends AnalyzerErrorCode { "to '{1}'.", hasPublishedDocs: true); + static const CompileTimeErrorCode FUNCTION_CLASS_DECLARATION = + CompileTimeErrorCode( + "FUNCTION_CLASS_DECLARATION", + "'Function' is a built-in identifier, could not used as a class name", + correction: "Try renaming the class.", + ); + + static const CompileTimeErrorCode FUNCTION_AS_TYPE_PARAMETER = + CompileTimeErrorCode( + "FUNCTION_AS_TYPE_PARAMETER", + "'Function' is a built-in identifier, could not used as a type parameter name", + correction: "Try renaming the type parameter.", + ); + + static const CompileTimeErrorCode FUNCTION_EXTENSION_DECLARATION = + CompileTimeErrorCode( + "FUNCTION_EXTENSION_DECLARATION", + "'Function' is a built-in identifier, could not used as a extension name", + correction: "Try renaming the extension.", + ); + + static const CompileTimeErrorCode FUNCTION_MIXIN_DECLARATION = + CompileTimeErrorCode( + "FUNCTION_MIXIN_DECLARATION", + "'Function' is a built-in identifier, could not used as a mixin name", + correction: "Try renaming the mixin.", + ); + /** * Initialize a newly created error code to have the given [name]. The message * associated with the error will be created from the given [message] diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 0d097e9a9ce3..bca53896dd70 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -609,6 +609,7 @@ class ErrorVerifier extends RecursiveAstVisitor _checkForBuiltInIdentifierAsName( name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME); } + _checkExtensionBadFunctionUse(node); super.visitExtensionDeclaration(node); _enclosingExtension = null; } @@ -959,6 +960,7 @@ class ErrorVerifier extends RecursiveAstVisitor _checkForMainFunction(node.name); _checkForWrongTypeParameterVarianceInSuperinterfaces(); // _checkForBadFunctionUse(node); + _checkMixinBasFunctionUse(node); super.visitMixinDeclaration(node); } finally { _enclosingClass = outerClass; @@ -1575,20 +1577,70 @@ class ErrorVerifier extends RecursiveAstVisitor } } + /// Verifies that the mixin is not named `Function` and that its type + /// parameters don't named `Function`. + void _checkMixinBasFunctionUse(MixinDeclaration node) { + final functionToken = "Function"; + var typeParams = node.typeParameters; + if (node.name.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, node.name); + } + if (typeParams != null) { + for (TypeParameter parameter in typeParams.typeParameters) { + if (parameter.name.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + } + } + } + } + + /// Verifies that the extension is not named `Function` and that its type + /// parameters don't named `Function`. + void _checkExtensionBadFunctionUse(ExtensionDeclaration node) { + final functionToken = "Function"; + var typeParams = node.typeParameters; + if (node.name != null && node.name?.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, node.name!); + } + if (typeParams != null) { + for (TypeParameter parameter in typeParams.typeParameters) { + if (parameter.name.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + } + } + } + } + /// Verifies that the class is not named `Function` and that it doesn't /// extends/implements/mixes in `Function`. + /// Also Verifies that the class's type parameters is not named `Function`. void _checkForBadFunctionUse(ClassDeclaration node) { var extendsClause = node.extendsClause; var withClause = node.withClause; + var typeParams = node.typeParameters; + final functionToken = "Function"; - if (node.name.name == "Function") { + if (node.name.name == functionToken) { errorReporter.reportErrorForNode( - HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, node.name); + CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, node.name); + } + + if (typeParams != null) { + for (TypeParameter parameter in typeParams.typeParameters) { + if (parameter.name.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + } + } } if (extendsClause != null) { var superElement = extendsClause.superclass.name.staticElement; - if (superElement != null && superElement.name == "Function") { + if (superElement != null && superElement.name == functionToken) { errorReporter.reportErrorForNode( HintCode.DEPRECATED_EXTENDS_FUNCTION, extendsClause.superclass); } @@ -1597,7 +1649,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (withClause != null) { for (TypeName type in withClause.mixinTypes) { var mixinElement = type.name.staticElement; - if (mixinElement != null && mixinElement.name == "Function") { + if (mixinElement != null && mixinElement.name == functionToken) { errorReporter.reportErrorForNode( HintCode.DEPRECATED_MIXIN_FUNCTION, type); } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart index 2e97f2543a6b..349f355f1b4e 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/src/dart/error/hint_codes.dart'; +import 'package:analyzer/src/error/codes.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; @@ -28,7 +29,7 @@ class A extends Function {} class Function {} class A extends Function {} ''', [ - error(HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), error(HintCode.DEPRECATED_EXTENDS_FUNCTION, 34, 8), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart new file mode 100644 index 000000000000..f56b195adb1f --- /dev/null +++ b/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:analyzer/src/dart/error/syntactic_errors.dart'; +import 'package:analyzer/src/error/codes.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import '../dart/resolution/context_collection_resolution.dart'; + +main() { + defineReflectiveSuite(() { + defineReflectiveTests(DeprecatedFunctionAsTypeIdentifierTest); + }); +} + +@reflectiveTest +class DeprecatedFunctionAsTypeIdentifierTest extends PubPackageResolutionTest { + test_typedef() async { + await assertErrorsInCode(''' +typedef Function = int; +typedef F = int; +''', [ + error(ParserErrorCode.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD, 8, 8), + ]); + } + + test_extension() async { + await assertErrorsInCode(''' +extension Function on List {} +extension E on List {} +''', [ + error(CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, 10, 8), + error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 42, 8), + ]); + } +} diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart index 6221d24ec8e4..8dce65648332 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/dart/error/hint_codes.dart'; +import 'package:analyzer/src/error/codes.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; @@ -19,7 +19,17 @@ class DeprecatedFunctionClassDeclarationTest extends PubPackageResolutionTest { await assertErrorsInCode(''' class Function {} ''', [ - error(HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), + ]); + } + + test_typeparameter() async { + await assertErrorsInCode(''' +class Function {} +class C {} +''', [ + error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 26, 8), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart index e6fd57e10cd0..d0b71086f8a2 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:analyzer/src/dart/error/hint_codes.dart'; +import 'package:analyzer/src/error/codes.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; import '../dart/resolution/context_collection_resolution.dart'; @@ -28,8 +29,18 @@ class A extends Object with Function {} class Function {} class A extends Object with Function {} ''', [ - error(HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), error(HintCode.DEPRECATED_MIXIN_FUNCTION, 46, 8), ]); } + + test_mixin() async { + await assertErrorsInCode(''' +mixin Function {} +mixin M implements List {} +''', [ + error(CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, 6, 8), + error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 26, 8), + ]); + } } diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart index 3d1234d84d1c..841874913aae 100644 --- a/pkg/analyzer/test/src/diagnostics/test_all.dart +++ b/pkg/analyzer/test/src/diagnostics/test_all.dart @@ -123,6 +123,8 @@ import 'definitely_unassigned_late_local_variable_test.dart' import 'deprecated_extends_function_test.dart' as deprecated_extends_function; import 'deprecated_function_class_declaration_test.dart' as deprecated_function_class_declaration; +import 'deprecated_function_as_type_identifier_test.dart' + as deprecated_function_as_type_identifier; import 'deprecated_member_use_test.dart' as deprecated_member_use; import 'deprecated_mixin_function_test.dart' as deprecated_mixin_function; import 'division_optimization_test.dart' as division_optimization; @@ -767,6 +769,7 @@ main() { definitely_unassigned_late_local_variable.main(); deprecated_extends_function.main(); deprecated_function_class_declaration.main(); + deprecated_function_as_type_identifier.main(); deprecated_member_use.main(); deprecated_mixin_function.main(); division_optimization.main(); From d0d0c85b1d23c077c7c28d0796a54103a849fe91 Mon Sep 17 00:00:00 2001 From: lfkdsk Date: Mon, 19 Apr 2021 15:28:21 +0800 Subject: [PATCH 2/4] feat: update mixin on function(). --- pkg/analyzer/lib/src/generated/error_verifier.dart | 13 +++++++++++++ .../diagnostics/deprecated_mixin_function_test.dart | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index bca53896dd70..603a3b97743e 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -1582,6 +1582,7 @@ class ErrorVerifier extends RecursiveAstVisitor void _checkMixinBasFunctionUse(MixinDeclaration node) { final functionToken = "Function"; var typeParams = node.typeParameters; + var onClause = node.onClause; if (node.name.name == functionToken) { errorReporter.reportErrorForNode( CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, node.name); @@ -1594,6 +1595,18 @@ class ErrorVerifier extends RecursiveAstVisitor } } } + // Check Mixin OnClause + if (onClause != null) { + for (TypeName type in onClause.superclassConstraints) { + var mixinElement = type.name.staticElement; + if (mixinElement != null && mixinElement.name == functionToken) { + errorReporter.reportErrorForNode( + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, type, + [type.name], + ); + } + } + } } /// Verifies that the extension is not named `Function` and that its type diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart index d0b71086f8a2..34a152efd80e 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart @@ -43,4 +43,12 @@ mixin M implements List {} error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 26, 8), ]); } + + test_mixin_onclause() async { + await assertErrorsInCode(''' +mixin A on Function {} +''', [ + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 11, 8), + ]); + } } From 9c5297a39dd255fbe57f721182749b10c431953c Mon Sep 17 00:00:00 2001 From: lfkdsk Date: Tue, 20 Apr 2021 12:03:16 +0800 Subject: [PATCH 3/4] fix as cr comments. --- pkg/analyzer/lib/error/error.dart | 4 --- pkg/analyzer/lib/src/error/codes.dart | 29 ------------------- .../lib/src/generated/error_verifier.dart | 15 ++++++---- .../deprecated_extends_function_test.dart | 2 +- ...ated_function_as_type_identifier_test.dart | 4 +-- ...cated_function_class_declaration_test.dart | 6 ++-- .../deprecated_mixin_function_test.dart | 7 +++-- .../test/src/diagnostics/test_all.dart | 6 ++-- 8 files changed, 22 insertions(+), 51 deletions(-) diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index ab96a3e8789e..ee91c887e300 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -461,10 +461,6 @@ const List errorCodeValues = [ CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR, CompileTimeErrorCode.YIELD_IN_NON_GENERATOR, CompileTimeErrorCode.YIELD_OF_INVALID_TYPE, - CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, - CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, - CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, - CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, FfiCode.ANNOTATION_ON_POINTER_FIELD, FfiCode.EMPTY_STRUCT, FfiCode.EXTRA_ANNOTATION_ON_STRUCT_FIELD, diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart index c6e770b23236..efe0821dab2f 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -13720,35 +13720,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode { "The type '{0}' implied by the 'yield' expression must be assignable " "to '{1}'.", hasPublishedDocs: true); - - static const CompileTimeErrorCode FUNCTION_CLASS_DECLARATION = - CompileTimeErrorCode( - "FUNCTION_CLASS_DECLARATION", - "'Function' is a built-in identifier, could not used as a class name", - correction: "Try renaming the class.", - ); - - static const CompileTimeErrorCode FUNCTION_AS_TYPE_PARAMETER = - CompileTimeErrorCode( - "FUNCTION_AS_TYPE_PARAMETER", - "'Function' is a built-in identifier, could not used as a type parameter name", - correction: "Try renaming the type parameter.", - ); - - static const CompileTimeErrorCode FUNCTION_EXTENSION_DECLARATION = - CompileTimeErrorCode( - "FUNCTION_EXTENSION_DECLARATION", - "'Function' is a built-in identifier, could not used as a extension name", - correction: "Try renaming the extension.", - ); - - static const CompileTimeErrorCode FUNCTION_MIXIN_DECLARATION = - CompileTimeErrorCode( - "FUNCTION_MIXIN_DECLARATION", - "'Function' is a built-in identifier, could not used as a mixin name", - correction: "Try renaming the mixin.", - ); - /** * Initialize a newly created error code to have the given [name]. The message * associated with the error will be created from the given [message] diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 603a3b97743e..23a95c13a150 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -1585,13 +1585,14 @@ class ErrorVerifier extends RecursiveAstVisitor var onClause = node.onClause; if (node.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, node.name); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name); } if (typeParams != null) { for (TypeParameter parameter in typeParams.typeParameters) { if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, + parameter); } } } @@ -1616,13 +1617,14 @@ class ErrorVerifier extends RecursiveAstVisitor var typeParams = node.typeParameters; if (node.name != null && node.name?.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, node.name!); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME, node.name!); } if (typeParams != null) { for (TypeParameter parameter in typeParams.typeParameters) { if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, + parameter); } } } @@ -1639,14 +1641,15 @@ class ErrorVerifier extends RecursiveAstVisitor if (node.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, node.name); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name); } if (typeParams != null) { for (TypeParameter parameter in typeParams.typeParameters) { if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, parameter); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, + parameter); } } } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart index 349f355f1b4e..4b8980b29194 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart @@ -29,7 +29,7 @@ class A extends Function {} class Function {} class A extends Function {} ''', [ - error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), error(HintCode.DEPRECATED_EXTENDS_FUNCTION, 34, 8), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart index f56b195adb1f..1b2b18de2271 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_function_as_type_identifier_test.dart @@ -30,8 +30,8 @@ typedef F = int; extension Function on List {} extension E on List {} ''', [ - error(CompileTimeErrorCode.FUNCTION_EXTENSION_DECLARATION, 10, 8), - error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 42, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME, 10, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 42, 8), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart index 8dce65648332..20171275c6ad 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart @@ -19,7 +19,7 @@ class DeprecatedFunctionClassDeclarationTest extends PubPackageResolutionTest { await assertErrorsInCode(''' class Function {} ''', [ - error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), ]); } @@ -28,8 +28,8 @@ class Function {} class Function {} class C {} ''', [ - error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), - error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 26, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 26, 8), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart index 34a152efd80e..622f7ac6651d 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart @@ -29,7 +29,7 @@ class A extends Object with Function {} class Function {} class A extends Object with Function {} ''', [ - error(CompileTimeErrorCode.FUNCTION_CLASS_DECLARATION, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), error(HintCode.DEPRECATED_MIXIN_FUNCTION, 46, 8), ]); } @@ -39,8 +39,9 @@ class A extends Object with Function {} mixin Function {} mixin M implements List {} ''', [ - error(CompileTimeErrorCode.FUNCTION_MIXIN_DECLARATION, 6, 8), - error(CompileTimeErrorCode.FUNCTION_AS_TYPE_PARAMETER, 26, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 26, + 8), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart index 841874913aae..ea6b88c1ce86 100644 --- a/pkg/analyzer/test/src/diagnostics/test_all.dart +++ b/pkg/analyzer/test/src/diagnostics/test_all.dart @@ -121,10 +121,10 @@ import 'deferred_import_of_extension_test.dart' as deferred_import_of_extension; import 'definitely_unassigned_late_local_variable_test.dart' as definitely_unassigned_late_local_variable; import 'deprecated_extends_function_test.dart' as deprecated_extends_function; -import 'deprecated_function_class_declaration_test.dart' - as deprecated_function_class_declaration; import 'deprecated_function_as_type_identifier_test.dart' as deprecated_function_as_type_identifier; +import 'deprecated_function_class_declaration_test.dart' + as deprecated_function_class_declaration; import 'deprecated_member_use_test.dart' as deprecated_member_use; import 'deprecated_mixin_function_test.dart' as deprecated_mixin_function; import 'division_optimization_test.dart' as division_optimization; @@ -768,8 +768,8 @@ main() { deferred_import_of_extension.main(); definitely_unassigned_late_local_variable.main(); deprecated_extends_function.main(); - deprecated_function_class_declaration.main(); deprecated_function_as_type_identifier.main(); + deprecated_function_class_declaration.main(); deprecated_member_use.main(); deprecated_mixin_function.main(); division_optimization.main(); From 95f9f4179300cdde227347ffb18f5612aac6d1cf Mon Sep 17 00:00:00 2001 From: lfkdsk Date: Tue, 20 Apr 2021 12:13:43 +0800 Subject: [PATCH 4/4] bugfix: fix error report and tests. --- .../lib/src/generated/error_verifier.dart | 15 +++++++++------ .../deprecated_extends_function_test.dart | 2 +- ...eprecated_function_class_declaration_test.dart | 4 ++-- .../deprecated_mixin_function_test.dart | 7 +++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 23a95c13a150..e43ffa2c89b5 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -1585,14 +1585,15 @@ class ErrorVerifier extends RecursiveAstVisitor var onClause = node.onClause; if (node.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name, + [functionToken]); } if (typeParams != null) { for (TypeParameter parameter in typeParams.typeParameters) { if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, - parameter); + parameter, [functionToken]); } } } @@ -1617,14 +1618,15 @@ class ErrorVerifier extends RecursiveAstVisitor var typeParams = node.typeParameters; if (node.name != null && node.name?.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME, node.name!); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME, node.name + !, [functionToken]); } if (typeParams != null) { for (TypeParameter parameter in typeParams.typeParameters) { if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, - parameter); + parameter, [functionToken]); } } } @@ -1641,7 +1643,8 @@ class ErrorVerifier extends RecursiveAstVisitor if (node.name.name == functionToken) { errorReporter.reportErrorForNode( - CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name); + CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, node.name, + [functionToken]); } if (typeParams != null) { @@ -1649,7 +1652,7 @@ class ErrorVerifier extends RecursiveAstVisitor if (parameter.name.name == functionToken) { errorReporter.reportErrorForNode( CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, - parameter); + parameter, [functionToken]); } } } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart index 4b8980b29194..3fdcffe64f87 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_extends_function_test.dart @@ -29,7 +29,7 @@ class A extends Function {} class Function {} class A extends Function {} ''', [ - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8), error(HintCode.DEPRECATED_EXTENDS_FUNCTION, 34, 8), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart index 20171275c6ad..52b0bff7d584 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_function_class_declaration_test.dart @@ -19,7 +19,7 @@ class DeprecatedFunctionClassDeclarationTest extends PubPackageResolutionTest { await assertErrorsInCode(''' class Function {} ''', [ - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8), ]); } @@ -28,7 +28,7 @@ class Function {} class Function {} class C {} ''', [ - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8), error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 26, 8), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart index 622f7ac6651d..eb27f2586891 100644 --- a/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart +++ b/pkg/analyzer/test/src/diagnostics/deprecated_mixin_function_test.dart @@ -29,7 +29,7 @@ class A extends Object with Function {} class Function {} class A extends Object with Function {} ''', [ - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8), error(HintCode.DEPRECATED_MIXIN_FUNCTION, 46, 8), ]); } @@ -39,9 +39,8 @@ class A extends Object with Function {} mixin Function {} mixin M implements List {} ''', [ - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 6, 8), - error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 26, - 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME, 6, 8), + error(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME, 26, 8), ]); }