Skip to content

[Inline classes] Report error on implements non-inline class #51564

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
modulovalue opened this issue Feb 28, 2023 · 1 comment
Closed

[Inline classes] Report error on implements non-inline class #51564

modulovalue opened this issue Feb 28, 2023 · 1 comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@modulovalue
Copy link
Contributor

Consider the following:

// Dart SDK version: 3.0.0-edge.0c32c7fc6295f329b8d8d74f640bdd77b0058c13 (be) (Fri Feb 24 07:45:06 2023 +0000) on "macos_arm64"
// ./dart run --enable-experiment=inline-class x.dart
void main() {
  print(0.foo());
}

abstract class Foo {
  int get t;
}

extension on int {
  Foo foo() => _FooImpl(this);
}

inline class _FooImpl implements Foo {
  final int t;

  const _FooImpl(this.t);
}

This fails to compile with:

Error: A value of type '_FooImpl' can't be returned from a function with return type 'Foo'.
 - 'Foo' is from 'package:foo/bar.dart' ('...').
  Foo foo() => _FooImpl(this);

If we remove the inline keyword then the program compiles as expected.

I'm wondering, is this a limitation of inline classes or is the experiment just not ready yet?

@lrhn
Copy link
Member

lrhn commented Feb 28, 2023

It's a limitation of inline classes. They cannot implement class interfaces, because an interface method is late-dispatch and inline classes are static-dispatch.

The implements Foo should be an error.

@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 Feb 28, 2023
@johnniwinther johnniwinther changed the title [Inline classes] hiding inline classes behind an interface not working. [Inline classes] Report error on implements non-inline class Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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