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

CFE gives incorrect type error for constant argument to extension type constructor. #53610

Closed
lrhn opened this issue Sep 26, 2023 · 1 comment
Assignees
Labels
cfe-feature-extension-types Implement extension types feature in the CFE feature-extension-types Implementation of the extension type feature legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Sep 26, 2023

Example:

extension type const N(Null _) {}
void main() {
  var n = N(null); // Works.
  const cn = N(null); // compile-time error.
}

This gives the errors:

badnone.dart:4:14: Error: Constant evaluation error:
  const cn = N(null); // compile-time error.
             ^
badnone.dart:1:23: Context: Expected constant 'null' to be of type 'N', but was of type 'Null'.
extension type const N(Null _) {}
                      ^
badnone.dart:4:9: Context: While analyzing:
  const cn = N(null); // compile-time error.
        ^

Analyzer has no error

Not sure which constant has which type, but the code is correct as written.
It seems to be a bug only in the constant evaluation, which does some type check using the wrong type.

@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. labels Sep 26, 2023
@johnniwinther johnniwinther added the feature-extension-types Implementation of the extension type feature label Sep 26, 2023
@lrhn
Copy link
Member Author

lrhn commented Oct 4, 2023

I keep hitting this issue with my attempts to write extension type examples.

If the constant evaluator effectively erases extension types, because it looks at the actual "runtime type" of the value for "runtime" type checks performed during constant evaluation, then it needs to do so consistently, also erasing in the type being checked against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cfe-feature-extension-types Implement extension types feature in the CFE feature-extension-types Implementation of the extension type feature legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants