Skip to content

[Extension types] Can extension type implement type Object? #53840

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 Oct 24, 2023 · 3 comments
Closed

[Extension types] Can extension type implement type Object? #53840

sgrekhov opened this issue Oct 24, 2023 · 3 comments
Labels
cfe-feature-extension-types Implement extension types feature in the CFE legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@sgrekhov
Copy link
Contributor

The following code works in analyzer but fails in CFE.

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

extension type ET(Object id) implements Object {} // CFE: Error: The type 'Object' can't be implemented by an extension type.

main() {
  print(ET);
}

@eernstg which tool wins here?

@mkustermann
Copy link
Member

/cc @lrhn

@eernstg
Copy link
Member

eernstg commented Oct 24, 2023

We don't have any rules against implements Object that I can find, so that would make it a CFE issue.

@eernstg eernstg transferred this issue from dart-lang/language Oct 24, 2023
@eernstg eernstg added the legacy-area-front-end Legacy: Use area-dart-model instead. label Oct 24, 2023
@johnniwinther johnniwinther added the cfe-feature-extension-types Implement extension types feature in the CFE label Oct 24, 2023
@lrhn
Copy link
Member

lrhn commented Oct 24, 2023

Agree. The types you just cannot implement are:

  • void
  • dynamic
  • T? for any T
  • FutureOr<T> for any T
  • Function
  • any function type
  • Record
  • any record type
  • Null
  • Never

That leaves only extension types and "interface types" (types of class, mixin or enum types) that are not mentioned above.

To implement any such type, T, the extension types with representation type R must satisfy at least one of the requirements:

  • R <: T, or
  • T is extension type with representation type R2 and R <: R2.

(Since the representation type now cannot be a bottom type, that also rules out implementing Never.)

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 legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

5 participants