Skip to content

augmented() in generative constructors needs additional compile-time checks #56477

Open
@eernstg

Description

@eernstg

The analyzer currently (ac9b6d1) does not report a compile-time error for the following program, in spite of the fact that augmented() is specified to have type void:

class A {
  A x;
  A() {
    print('Running introductory!');
  }
  augment A(): x = augmented();
}

Also, the expression augmented() should evaluate to null, which means that it would be a soundness violation to allow it to be used as the initial value of x.

Another program which is accepted by the analyzer with no compile-time errors is the following:

class A {
  dynamic x;
  A() {
    print('Running introductory!');
  }
  augment A(): x = augmented();
}

In this case I believe there must also be an error (this is discussed in dart-lang/language#4039), even though the above mentioned soundness violation does not exist.

A similar situation exists with a redirecting generative constructor where this(augmented()) does not cause any compile-time errors.

class B {
  B(Object? o);
  B.named(): this(42);
  augment B.named(): this(augmented());
}

In this case there should be an error because an expression of type void (namely augmented()) occurs in a location where an Object? is expected, and it is not on the allowlist for using the value of an expression of type void.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-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 specfeature-augmentationsImplementation of the augmentations featuretype-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