Skip to content

Allow generic metadata annotations #1297

@ghost

Description

Feature specification: https://github.com/dart-lang/language/blob/master/accepted/2.14/small-features-21Q1/feature-specification.md


Annotations (metadata) aren't allowed to use type arguments, but it is allowed to make annotations using a const of a type that takes a type argument:

class MyAnnotation<T> {
  const MyAnnotation();
}

const MA = MyAnnotation<String Function(int)>();

@MA  // <- Works.
random(int weather) => '7';

@MyAnnotation<String Function(int)>()  // <- Fails.
alsoRandom(int lucky) => '7';

main() => random(0) + alsoRandom(13);

Gives:

../../annotation_type_generic.dart:10:14: Error: An annotation (metadata) can't use type arguments.
@MyAnnotation<String Function(int)>()
             ^

See also: dart-lang/sdk#44120

Metadata

Metadata

Assignees

Labels

small-featureA small feature which is relatively cheap to implement.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions