Skip to content

[CFE] No error in CFE if an extension type is not well-bounded #54097

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

Closed
sgrekhov opened this issue Nov 20, 2023 · 2 comments
Closed

[CFE] No error in CFE if an extension type is not well-bounded #54097

sgrekhov opened this issue Nov 20, 2023 · 2 comments
Assignees
Labels
cfe-feature-extension-types Implement extension types feature in the CFE feature-extension-types Implementation of the extension type feature front-end-missing-error legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@sgrekhov
Copy link
Contributor

The following program produces an expected error in analyzer but not in CFE

// SharedOptions=--enable-experiment=inline-class

extension type V<T extends V<T>>(T id) {}
//                         ^
// [analyzer] unspecified
// [cfe] unspecified

main() {
  print(V<Never>);
}

After extension type erasure we'll have here extension type V<T extends T>(T id) {} which is an error. So, analyzer correctly expects COMPILE_TIME_ERROR.TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND here

Tested on Dart SDK version: 3.3.0-edge.5918e012cc875df2b96ec25e3fee0de263feed80 (main) (Mon Nov 20 08:03:39 2023 +0000) on "linux_x64"

@sgrekhov sgrekhov added legacy-area-front-end Legacy: Use area-dart-model instead. front-end-missing-error cfe-feature-extension-types Implement extension types feature in the CFE labels Nov 20, 2023
@chloestefantsova
Copy link
Contributor

Thanks for reporting that, @sgrekhov! As far as I understand, the related passage in the spec is the following:

Let X1 extends B1, .. Xs extends Bs be a declaration of the type parameters of a generic entity (it could be a generic class, extension type, mixin, typedef, or function). Let BBj be the extension type erasure of Bj, for j in 1 .. s. It is a compile-time error if X1 extends BB1, .. Xs extends BBs has any compile-time errors.

Also, the compile-time message emitted by the Analyzer could be more helpful. Currently it says 'T' can't be a supertype of its upper bound., even though T is not a supertype of its bound, V<T>.

@chloestefantsova chloestefantsova self-assigned this Nov 20, 2023
copybara-service bot pushed a commit that referenced this issue Dec 15, 2023
This reverts commit 9bb61c0.

Reason for revert: NPE detected in google3.

Original change's description:
> [cfe] Check type variable dependency cycles via extension types
>
> Closes #54097
> Closes #54164
> Part of #49731
>
> Change-Id: I73aac5f7e2c7f05fd0872b37e6f39fa7b5ed4862
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337183
> Commit-Queue: Chloe Stefantsova <[email protected]>
> Reviewed-by: Johnni Winther <[email protected]>

Change-Id: If1e102112546e333f2e7058e432af142ce7da56e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341922
Bot-Commit: Rubber Stamper <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>
Auto-Submit: Chloe Stefantsova <[email protected]>
@eernstg
Copy link
Member

eernstg commented Dec 15, 2023

has any compile-time errors.

I don't know if this is obvious, but the transformation that replaces each bound by its extension type erasure could of course create compile-time errors in the body whenever a receiver has a type which is a type variable, and it used to invoke an extension type member (but when the bound is no longer that extension type, the member does not exist, or it has a different member signature). So we're only requiring that it would not be an error of a type parameter to declare the type parameters as bounded by the extension type erasures, we don't care that there could be errors where the type parameter is used.

@lrhn lrhn added the feature-extension-types Implementation of the extension type feature label Dec 15, 2023
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 front-end-missing-error legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

4 participants