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, language] Different results for a private field overrides if mixin application is moved to a different library #50374

Closed
annagrin opened this issue Nov 3, 2022 · 4 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-as-intended Closed as the reported issue is expected behavior

Comments

@annagrin
Copy link
Contributor

annagrin commented Nov 3, 2022

Not sure if this is a bug or intended behavior. CFE uses symbols for _foo from the current library in main(), which is different from the symbol for B._foo if class B is defined in a separate library.

This came up in fixing a DDC issue #50119, which resulted in a stack overflow in C()._foo if B was defined in a separate library. I am updating DDC to match other compilers' behavior (described below).

//import 'b.dart';

void main() {
  print('c._foo: ${C()._foo}');  // 'A.foo' if class B is defined in a separate library, 'B._foo' otherwise
  print('d._foo: ${D()._foo}');  // 'A.foo' if class B is defined in a separate library, 'B._foo' otherwise
  print('e._foo: ${E()._foo}');  // 'E._foo'

class C = A with B;

class D extends A with B {}

class E extends A with B {
  String? _foo = 'E._foo';
}

class A {
  String? _foo = 'A._foo';
}

// move this to a separate library b.dart to get different results in main
class B {
  String? _foo = 'B._foo';
}
@annagrin annagrin added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Nov 3, 2022
@annagrin
Copy link
Contributor Author

annagrin commented Nov 3, 2022

@leafpetersen I wonder if the behavior above is intended from the language perspective?

@annagrin
Copy link
Contributor Author

annagrin commented Nov 3, 2022

/cc @nshahan

@lrhn
Copy link
Member

lrhn commented Nov 3, 2022

This does sound like intended behavior.

Library private names, those starting with _, behave differently depending on whether they are in the same library or in another.

Moving something with a private member to another library is equivalent to renaming every private member to something else, to a name which the original library doesn't use at all.
So, moving the B declaration to a different library means that its _foo member no longer has the same name as the _foo members of the current library, and therefore no longer override A._foo.

@annagrin
Copy link
Contributor Author

annagrin commented Nov 3, 2022

Thanks @lrhn for clarification, will close this as intended then.

@annagrin annagrin closed this as completed Nov 3, 2022
@annagrin annagrin added the closed-as-intended Closed as the reported issue is expected behavior label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants