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

DDC: Mixing in an implementer of a covariant field or setter results in getter that always returns null #46867

Closed
greglittlefield-wf opened this issue Aug 10, 2021 · 2 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dev-compiler

Comments

@greglittlefield-wf
Copy link
Contributor

greglittlefield-wf commented Aug 10, 2021

Mixing in an implementer of a covariant field or setter and then concretely implementing that member with another class can result in the target class's getter always returning null in DDC-compiled code. Potentially a similar issue to #29914 (see below).

Reduced test case:

void main() {
  // Prints 'null', not 'foo from BaseClass' as expected, or even 'foo from Interface'.
  print('SubClass().foo');
  print(SubClass().foo);

  // Setting the value works as expected, though; 
  // this prints 'set foo in BaseClass' as expected.
  SubClass().foo = 'bar';
}

class Interface {
  // This can be a getter and covariant setter or a covariant field.
  covariant Object foo = 'foo from Interface';
}

mixin Mixin implements Interface {}

class BaseClass {
  // This can be a getter/setter or another field.
  Object get foo => 'foo from BaseClass';
  set foo(Object value) {
    print('set foo in BaseClass');
  }
}

// BaseClass.foo satisfies the need to concretely implement Interface.foo when mixed in.
// This issue can also be reproduced by mixing in BaseClass instead of extending it.
class SubClass extends BaseClass with Mixin {}

I noticed that the issue does not occur if you tweak this code by either:

  • Adding implements Interface to BaseClass
  • Moving implements Interface from Mixin to BaseClass
  • Making Interface.foo non-covariant

When logging this class to the console, you can see that there's a setter declared in one of the objects in the prototype chain without a corresponding getter. This seems like a similar issue to #29914, so perhaps the fix is also something similar?

Screen Shot 2021-08-09 at 6 47 41 PM

Dart SDKs I've checked in which the issue occurs:

  • Dart 2.14.0-377.0.dev (I only tried with null safety enabled)
  • Dart 2.13.3 (both with and without null safety enabled)
  • Dart 2.12.0 (I only tried without null safety enabled)

Dart SDKs I've checked in which the issue does not occur:

  • Dart 2.10.4
  • Dart 2.9.0
  • Dart 2.7.2
@vsmenon vsmenon added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dev-compiler labels Aug 10, 2021
@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Aug 10, 2021
@nshahan
Copy link
Contributor

nshahan commented Aug 10, 2021

@greglittlefield-wf Thanks for the minimal reproduction and the detailed investigation. I think I see what the bug is here and I'm testing a fix. The setter with a covariant parameter is causing the synthetic mixin class in the hierarchy to generate a forwarding setter. It should have a matching forwarding getter because there is a getter higher up the class hierarchy but it's missing.

dart-bot pushed a commit that referenced this issue Aug 17, 2021
Issue: #46867
Change-Id: I7e2912752ac8c48df233f27869599280e2c322fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209853
Reviewed-by: Mark Zhou <[email protected]>
Commit-Queue: Nicholas Shahan <[email protected]>
@greglittlefield-wf
Copy link
Contributor Author

@nshahan Np, thank you for fixing this issue so quickly!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dev-compiler
Projects
None yet
Development

No branches or pull requests

4 participants