Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eernstg opened this issue Aug 15, 2024 · 0 comments
Open
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Aug 15, 2024

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.

@eernstg eernstg added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) analyzer-spec Issues with the analyzer's implementation of the language spec feature-augmentations Implementation of the augmentations feature labels Aug 15, 2024
@keertip keertip added the P2 A bug or feature request we're likely to work on label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants