Skip to content

Front-end does not allow non-static constant variables as annotations #37065

@lrhn

Description

@lrhn

Example:

const x = 0;
main(@x args) {
  const z = 0;
  foo(@z args) {}
  bar(@x args) {}  // local too.
}

This uses both constant variables x and z as an annotations on function arguments.
The @x annotation is allowed, but the @z annotation is rejected with:

annot.dart:4:8: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  foo(@z args) {}
       ^

The analyzer accepts the program, and the front-end should too since z is a reference to a compile-time constant variable.

Metadata

Metadata

Labels

legacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions