Skip to content

Scoping behavior of annotations disagrees with spec #1790

Closed
@stereotype441

Description

@stereotype441

The following weird program is accepted by both the analyzer and the CFE:

class A {
  const A(void Function() x);
}
class C<@A(B) T> {
  static void B() {}
}
main() {
  new C<int>();
}

This seems to contradict the spec, which says "Type parameters are declared in the type parameter scope of a class or function" (15 Generics) and "The constant expression given in an annotation is type checked and evaluated in the scope surrounding the declaration being annotated" (16 Metadata). Together these seems to imply that the reference to B in @A(B) should be an error, because there is no declaration of B in scope.

Metadata

Metadata

Assignees

Labels

bugThere is a mistake in the language specification or in an active document

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions