Report EXPERIMENT_NOT_ENABLED instead of ANNOTATION_WITH_TYPE_ARGUMENTS.

On one hand this is less precise, OTOH this tells which feature and
the language version it requires.

Change-Id: I1d24a2d7cf2c7b7ca305d5bfc9f094fce0734bc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210644
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-08-19 20:20:26 +00:00 committed by commit-bot@chromium.org
parent c929388181
commit 4d42e73295
6 changed files with 31 additions and 25 deletions

View file

@ -23,7 +23,6 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
messageInvalidInitializer,
messageInvalidSuperInInitializer,
messageInvalidThisInInitializer,
messageMetadataTypeArguments,
messageMissingAssignableSelector,
messageNativeClauseShouldBeAnnotation,
messageOperatorWithTypeParameters,
@ -1867,8 +1866,15 @@ class AstBuilder extends StackListener {
var typeArguments = pop() as TypeArgumentList?;
if (typeArguments != null &&
!_featureSet.isEnabled(Feature.generic_metadata)) {
handleRecoverableError(messageMetadataTypeArguments,
typeArguments.beginToken, typeArguments.beginToken);
var feature = Feature.generic_metadata;
handleRecoverableError(
templateExperimentNotEnabled.withArguments(
feature.enableString,
_versionAsString(feature.releaseVersion!),
),
typeArguments.beginToken,
typeArguments.beginToken,
);
}
var name = pop() as Identifier;
push(ast.annotation(

View file

@ -49,8 +49,8 @@ class GenericMetadataEnabledParserTest extends FastaParserTestCase
mixin GenericMetadataParserTest on FastaParserTestCase {
void test_className_prefixed_constructorName_absent() {
var compilationUnit = _parseCompilationUnit('@p.A<B>() class C {}',
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 4, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 4, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -65,8 +65,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
void test_className_prefixed_constructorName_present() {
var compilationUnit = _parseCompilationUnit('@p.A<B>.ctor() class C {}',
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 4, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 4, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -81,8 +81,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
void test_className_unprefixed_constructorName_absent() {
var compilationUnit = _parseCompilationUnit('@A<B>() class C {}',
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 2, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 2, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -96,8 +96,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
void test_className_unprefixed_constructorName_present() {
var compilationUnit = _parseCompilationUnit('@A<B>.ctor() class C {}',
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 2, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 2, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -117,8 +117,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
6,
1),
],
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 4, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 4, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -139,8 +139,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
4,
1),
],
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 2, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 2, 1));
var classDeclaration =
compilationUnit.declarations.single as ClassDeclaration;
var annotation = classDeclaration.metadata.single;
@ -174,8 +174,8 @@ mixin GenericMetadataParserTest on FastaParserTestCase {
expectedError(ParserErrorCode.EXPECTED_EXECUTABLE, 7, 1),
expectedError(ParserErrorCode.MISSING_FUNCTION_BODY, 15, 5),
],
disabledError: expectedError(
ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS, 2, 1));
disabledError:
expectedError(ParserErrorCode.EXPERIMENT_NOT_ENABLED, 2, 1));
}
CompilationUnit _parseCompilationUnit(String content,

View file

@ -17,11 +17,11 @@ main() {
@C()
@C<dynamic>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
@C<int>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
int i = 0;
ignore(i);

View file

@ -13,10 +13,10 @@ class C<T> {
@C()
@C<dynamic>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
@C<int>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
main() {}

View file

@ -19,11 +19,11 @@ main() {
@C()
@C<dynamic>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
@C<int>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
int i = 0;
ignore(i);

View file

@ -15,10 +15,10 @@ class C<T> {
@C()
@C<dynamic>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
@C<int>()
//^
// [analyzer] SYNTACTIC_ERROR.ANNOTATION_WITH_TYPE_ARGUMENTS
// [analyzer] SYNTACTIC_ERROR.EXPERIMENT_NOT_ENABLED
// [cfe] An annotation can't use type arguments.
main() {}