Skip to content

Resolution / inference in ElementAnnotationImpl.annotationAst is incomplete #34894

Open
@scheglov

Description

@scheglov

The following test, when added to ClassResolutionMixin, passes with task model, and fails with AnalysisDriver.

  Expected: 'List<num>'
    Actual: 'null'

The failure disappears if I move class C {} with its annotation into the test file.

That's because we clone the annotation and store into the element model.

Which does not help to clients that use just element model and look at annotations from other files, possibly resynthesized from summaries.

  solo_test_XXX() async {
    newFile('/test/lib/a.dart', content: r'''
class A {
  final x;
  const A(this.x);
}

@A([1, 2.3])
class C {}
''');
    addTestFile(r'''
import 'a.dart';

C c;
''');
    await resolveTestFile();
    assertNoTestErrors();

    ClassElement c = findNode.simple('C c').staticElement;
    ElementAnnotationImpl m = c.metadata[0];
    var listType = m.annotationAst.arguments.arguments[0].staticType;
    assertElementTypeString(listType, 'List<num>');
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-analyzer-specIssues with the analyzer's implementation of the language spectype-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