[analyzer] Variance: out and inout are no longer built-in keywords. The feature spec has removed the requirement for `out` and `inout` to be buit-in keywords: https://github.com/dart-lang/language/blob/main/working/0524-variance/feature-specification.md#syntax This CL removes that extra case we had for the analyzer and adds a few tests, making sure we reverted the previous change for those keywords to be built-in. Bug: https://github.com/dart-lang/sdk/issues/65071 Change-Id: I972dea399e354d9d3c84e3d581e0fd9818f21433 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/582121 Commit-Queue: Kallen Tu <kallentu@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index c00ffc7..755a068 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -3763,15 +3763,6 @@ diagnosticReporter.report( code.withArguments(name: token.lexeme).at(token), ); - return; - } - - if (_featureSet.isEnabled(Feature.variance)) { - if (token.keyword == Keyword.INOUT || token.keyword == Keyword.OUT) { - diagnosticReporter.report( - code.withArguments(name: token.lexeme).at(token), - ); - } } }
diff --git a/pkg/analyzer/test/generated/variance_parser_test.dart b/pkg/analyzer/test/generated/variance_parser_test.dart index fb712f7..ba5047c 100644 --- a/pkg/analyzer/test/generated/variance_parser_test.dart +++ b/pkg/analyzer/test/generated/variance_parser_test.dart
@@ -221,6 +221,51 @@ '''); } + void test_class_enabled_outAndInoutAsNames() { + var parseResult = parseTestCodeWithDiagnostics( + 'class A<out out, inout inout> { }', + featureSet: _enabledFeatureSet, + ); + + var node = parseResult.findNode.singleClassDeclaration; + assertParsedNodeText(node, r''' +ClassDeclaration2 + classKeyword: class + namePart: NameWithTypeParameters + typeName: A + typeParameters: TypeParameterList + leftBracket: < + typeParameters + TypeParameter + varianceKeyword: out + name: out + TypeParameter + varianceKeyword: inout + name: inout + rightBracket: > + body: BlockInstanceDeclarationBody + leftBracket: { + rightBracket: } +V1: ClassDeclaration + classKeyword: class + namePart: NameWithTypeParameters + typeName: A + typeParameters: TypeParameterList + leftBracket: < + typeParameters + TypeParameter + varianceKeyword: out + name: out + TypeParameter + varianceKeyword: inout + name: inout + rightBracket: > + body: BlockClassBody + leftBracket: { + rightBracket: } +'''); + } + void test_class_enabled_single() { var parseResult = parseTestCodeWithDiagnostics( 'class A<in T> { }',
diff --git a/pkg/analyzer/test/src/dart/resolution/variance_test.dart b/pkg/analyzer/test/src/dart/resolution/variance_test.dart index eabf08b..09db155 100644 --- a/pkg/analyzer/test/src/dart/resolution/variance_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/variance_test.dart
@@ -181,4 +181,46 @@ Upper '''); } + + test_outAndInoutAsNames_classAndMixin() async { + await resolveTestCodeWithDiagnostics(r''' +class out<inout> {} + +mixin inout<out> {} +'''); + } + + test_outAndInoutAsNames_classicTypedef() async { + await resolveTestCodeWithDiagnostics(r''' +typedef void out(); + +typedef void inout(); +'''); + } + + test_outAndInoutAsNames_enumAndClassTypeAlias() async { + await resolveTestCodeWithDiagnostics(r''' +enum out { a } + +mixin M {} + +class inout = Object with M; +'''); + } + + test_outAndInoutAsNames_extensionTypeAndPrefix() async { + await resolveTestCodeWithDiagnostics(r''' +import 'dart:async' as inout; + +extension type out(inout.Future<int> it) {} +'''); + } + + test_outAndInoutAsNames_typedefAndExtension() async { + await resolveTestCodeWithDiagnostics(r''' +typedef out<inout> = void Function(inout); + +extension inout<out> on List<out> {} +'''); + } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart index 44d5679..a309c4b 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_name_test.dart
@@ -31,34 +31,4 @@ // [diag.builtInIdentifierAsExtensionName] The built-in identifier 'Function' can't be used as an extension name. '''); } - - test_inout() async { - await resolveTestCodeWithDiagnostics(r''' -extension inout on Object {} -// ^^^^^ -// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'inout' can't be used as an extension name. -'''); - } - - test_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -extension inout on Object {} -'''); - } - - test_out() async { - await resolveTestCodeWithDiagnostics(r''' -extension out on Object {} -// ^^^ -// [diag.builtInIdentifierAsExtensionName] The built-in identifier 'out' can't be used as an extension name. -'''); - } - - test_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -extension out on Object {} -'''); - } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart index bce79e9..21a3406 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_extension_type_name_test.dart
@@ -32,34 +32,4 @@ // [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'Function' can't be used as an extension type name. '''); } - - test_inout() async { - await resolveTestCodeWithDiagnostics(r''' -extension type inout(int it) {} -// ^^^^^ -// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'inout' can't be used as an extension type name. -'''); - } - - test_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -extension type inout(int it) {} -'''); - } - - test_out() async { - await resolveTestCodeWithDiagnostics(r''' -extension type out(int it) {} -// ^^^ -// [diag.builtInIdentifierAsExtensionTypeName] The built-in identifier 'out' can't be used as an extension type name. -'''); - } - - test_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -extension type out(int it) {} -'''); - } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart index 5bac9c2..95ae281 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_prefix_name_test.dart
@@ -35,42 +35,4 @@ // [diag.builtInIdentifierAsPrefixName] The built-in identifier 'Function' can't be used as a prefix name. '''); } - - test_inout() async { - await resolveTestCodeWithDiagnostics(r''' -import 'dart:async' as inout; -// ^^^^^^^^^^^^ -// [diag.unusedImport] Unused import: 'dart:async'. -// ^^^^^ -// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'inout' can't be used as a prefix name. -'''); - } - - test_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -import 'dart:async' as inout; -// ^^^^^^^^^^^^ -// [diag.unusedImport] Unused import: 'dart:async'. -'''); - } - - test_out() async { - await resolveTestCodeWithDiagnostics(r''' -import 'dart:async' as out; -// ^^^^^^^^^^^^ -// [diag.unusedImport] Unused import: 'dart:async'. -// ^^^ -// [diag.builtInIdentifierAsPrefixName] The built-in identifier 'out' can't be used as a prefix name. -'''); - } - - test_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -import 'dart:async' as out; -// ^^^^^^^^^^^^ -// [diag.unusedImport] Unused import: 'dart:async'. -'''); - } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart index 167c8c9..ceeee8f 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_name_test.dart
@@ -32,36 +32,6 @@ '''); } - test_class_inout() async { - await resolveTestCodeWithDiagnostics(r''' -class inout {} -// ^^^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. -'''); - } - - test_class_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class inout {} -'''); - } - - test_class_out() async { - await resolveTestCodeWithDiagnostics(r''' -class out {} -// ^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. -'''); - } - - test_class_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class out {} -'''); - } - test_enum_as() async { await resolveTestCodeWithDiagnostics(r''' enum as { @@ -72,36 +42,6 @@ '''); } - test_enum_inout() async { - await resolveTestCodeWithDiagnostics(r''' -enum inout {v} -// ^^^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. -'''); - } - - test_enum_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -enum inout {v} -'''); - } - - test_enum_out() async { - await resolveTestCodeWithDiagnostics(r''' -enum out {v} -// ^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. -'''); - } - - test_enum_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -enum out {v} -'''); - } - test_mixin_as() async { await resolveTestCodeWithDiagnostics(r''' mixin as {} @@ -118,21 +58,6 @@ '''); } - test_mixin_inout() async { - await resolveTestCodeWithDiagnostics(r''' -mixin inout {} -// ^^^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'inout' can't be used as a type name. -'''); - } - - test_mixin_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -mixin inout {} -'''); - } - test_mixin_OK_on() async { await resolveTestCodeWithDiagnostics(r''' class A {} @@ -148,19 +73,4 @@ class D = Object with M2; '''); } - - test_mixin_out() async { - await resolveTestCodeWithDiagnostics(r''' -mixin out {} -// ^^^ -// [diag.builtInIdentifierAsTypeName] The built-in identifier 'out' can't be used as a type name. -'''); - } - - test_mixin_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -mixin out {} -'''); - } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart index 1ed15e7..29d8dcc 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_type_parameter_name_test.dart
@@ -33,36 +33,6 @@ '''); } - test_class_inout() async { - await resolveTestCodeWithDiagnostics(r''' -class A<inout> {} -// ^^^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. -'''); - } - - test_class_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class A<inout> {} -'''); - } - - test_class_out() async { - await resolveTestCodeWithDiagnostics(r''' -class A<out> {} -// ^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. -'''); - } - - test_class_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class A<out> {} -'''); - } - test_extension_as() async { await resolveTestCodeWithDiagnostics(r''' extension <as> on List {} @@ -71,22 +41,6 @@ '''); } - test_extension_inout() async { - await resolveTestCodeWithDiagnostics(r''' -extension <inout> on List {} -// ^^^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. -'''); - } - - test_extension_out() async { - await resolveTestCodeWithDiagnostics(r''' -extension <out> on List {} -// ^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. -'''); - } - test_function_as() async { await resolveTestCodeWithDiagnostics(r''' void f<as>() {} @@ -94,20 +48,4 @@ // [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'as' can't be used as a type parameter name. '''); } - - test_function_inout() async { - await resolveTestCodeWithDiagnostics(r''' -void f<inout>() {} -// ^^^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'inout' can't be used as a type parameter name. -'''); - } - - test_function_out() async { - await resolveTestCodeWithDiagnostics(r''' -void f<out>() {} -// ^^^ -// [diag.builtInIdentifierAsTypeParameterName] The built-in identifier 'out' can't be used as a type parameter name. -'''); - } }
diff --git a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart index 1c44101..cd1f8d5 100644 --- a/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/built_in_identifier_as_typedef_name_test.dart
@@ -26,44 +26,6 @@ '''); } - test_classTypeAlias_inout() async { - await resolveTestCodeWithDiagnostics(r''' -class A {} -mixin B {} -class inout = A with B; -// ^^^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. -'''); - } - - test_classTypeAlias_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class A {} -mixin B {} -class inout = A with B; -'''); - } - - test_classTypeAlias_out() async { - await resolveTestCodeWithDiagnostics(r''' -class A {} -mixin B {} -class out = A with B; -// ^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. -'''); - } - - test_classTypeAlias_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -class A {} -mixin B {} -class out = A with B; -'''); - } - test_typedef_classic() async { await resolveTestCodeWithDiagnostics(r''' typedef void as(); @@ -82,36 +44,6 @@ '''); } - test_typedef_classic_inout() async { - await resolveTestCodeWithDiagnostics(r''' -typedef void inout(); -// ^^^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. -'''); - } - - test_typedef_classic_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -typedef void inout(); -'''); - } - - test_typedef_classic_out() async { - await resolveTestCodeWithDiagnostics(r''' -typedef void out(); -// ^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. -'''); - } - - test_typedef_classic_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -typedef void out(); -'''); - } - test_typedef_generic_as() async { await resolveTestCodeWithDiagnostics(r''' typedef as = void Function(); @@ -121,36 +53,6 @@ '''); } - test_typedef_generic_inout() async { - await resolveTestCodeWithDiagnostics(r''' -typedef inout = void Function(); -// ^^^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'inout' can't be used as a typedef name. -'''); - } - - test_typedef_generic_inout_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -typedef inout = void Function(); -'''); - } - - test_typedef_generic_out() async { - await resolveTestCodeWithDiagnostics(r''' -typedef out = void Function(); -// ^^^ -// [diag.builtInIdentifierAsTypedefName] The built-in identifier 'out' can't be used as a typedef name. -'''); - } - - test_typedef_generic_out_beforePrimaryConstructors() async { - await resolveTestCodeWithDiagnostics(r''' -// %before-language-feature: primary-constructors -typedef out = void Function(); -'''); - } - test_typedef_interfaceType_as() async { await resolveTestCodeWithDiagnostics(r''' typedef as = List<int>;
diff --git a/tests/language/variance/syntax/variance_syntax_test.dart b/tests/language/variance/syntax/variance_syntax_test.dart index fd672e4..9a40965 100644 --- a/tests/language/variance/syntax/variance_syntax_test.dart +++ b/tests/language/variance/syntax/variance_syntax_test.dart
@@ -27,6 +27,10 @@ class F<out T> = Object with D<T>; +class G<out out> {} + +class H<out inout> {} + main() { B<int, String, bool> b = B(); @@ -34,4 +38,8 @@ Expect.equals(2, c.foo(3)); F<int> f = F(); + + G<int> g = G(); + + H<int> h = H(); }
diff --git a/tests/language/variance/syntax/variance_type_parameter_error_syntax_test.dart b/tests/language/variance/syntax/variance_type_parameter_error_syntax_test.dart index a165d38..b88a28e 100644 --- a/tests/language/variance/syntax/variance_type_parameter_error_syntax_test.dart +++ b/tests/language/variance/syntax/variance_type_parameter_error_syntax_test.dart
@@ -63,15 +63,11 @@ // [cfe] Each type parameter can have at most one variance modifier. typedef E<out T> = T Function(T a); -// ^^^ -// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. extension Extension<out T> on List<T> {} -// ^^^ -// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. @@ -87,23 +83,17 @@ class Methods { static void staticMethod<inout T>() {} - // ^^^^^ - // [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. void instanceMethod<out T>() {} - // ^^^ - // [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. } typedef NonFunctionAlias<out T> = List<T>; -// ^^^ -// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. @@ -129,15 +119,11 @@ // [cfe] Expected a function body or '=>'. typedef void OldStyleFunctionAlias<inout T>(T x); -// ^^^^^ -// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. void Function<out T>()? genericFunctionType; -// ^^^ -// [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this. @@ -162,8 +148,6 @@ // [cfe] Expected ';' after this. var functionLiteral = <out T>() {}; - // ^^^ - // [analyzer] COMPILE_TIME_ERROR.BUILT_IN_IDENTIFIER_IN_DECLARATION // ^ // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN // [cfe] Expected ',' before this.