Skip to content

redirectedConstructor apparently changed behavior, is that intended? #41071

@eernstg

Description

@eernstg

Cf. https://dart-review.googlesource.com/c/sdk/+/139800, which adds the following new test to 'pkg/analyzer/test/generated/parser_test.dart':

  void test_parseClassMember_redirectingGenerativeConstructor() {
    createParser('C.redirecting(): this();');
    var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
    assertNoErrors();
    expect(constructor, isNotNull);
    expect(constructor.externalKeyword, isNull);
    expect(constructor.constKeyword, isNull);
    expect(constructor.factoryKeyword, isNull);
    expect(constructor.returnType.name, 'C');
    expect(constructor.period.type, TokenType.PERIOD);
    expect(constructor.name.name, 'redirecting');
    _assertIsDeclarationName(constructor.returnType, false);
    expect(constructor.parameters, isNotNull);
    expect(constructor.parameters.parameters, isEmpty);
    expect(constructor.separator.type, TokenType.COLON);
    expect(constructor.initializers, hasLength(1));
    ConstructorInitializer initializer = constructor.initializers[0];
    expect(initializer is RedirectingConstructorInvocation, isTrue);
    expect(constructor.redirectedConstructor, isNotNull); // FAILS.
    // expect(constructor.redirectedConstructor.type.name.name, '???');
    // expect(constructor.redirectedConstructor.period, isNull);
    expect(constructor.body, isEmptyFunctionBody);
  }

The interesting part is at the line with the comment // FAILS.. This shows that the redirectedConstructor is null. This behavior is new (it caused a 'reflectable' test to start failing), and it seems likely that it is a bug.

In particular, the redirectedConstructor is also null when the constructor declaration uses this.name(), and this makes it impossible to make the distinction between redirection to different constructors, at least via redirectedConstructor.

The failure in the CFE and in the analyzer can be reproduced locally as follows:

> python tools/test.py -n cfe-unittest-asserts-release-linux pkg/analyzer/test/generated/parser_fasta_test
> python tools/test.py -n analyzer-unittest-asserts-release-linux pkg/analyzer/test/generated/parser_fasta_test

I have chosen 'area-front-end' for this because the issue arises during parsing in both configurations, and because the analyzer uses the front end parser to some extent.

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-packageIssues related to package:analyzertype-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