Skip to content

DDC: Mixed in setter overrides of private fields are called unexpectedly during instantiation #36217

Description

@greglittlefield-wf

In the DDC, when a mixin introduces a setter that overrides a private field, that setter is called unexpectedly during object initialization.

This seems to happen because the class is attempting to initialize the property backing that field to null, but ends up going through the setter instead unexpectedly.

This affects over_react, and we currently have a less-than-ideal workaround in place for this bug.

Reduced test case:

main() {
  // Prints "_privateVar setter called" unexpectedly.
  new C();
}

class A {
  var _privateVar;
}

mixin B on A {
  @override
  get _privateVar {
    print('_privateVar getter called');
  }
  @override
  set _privateVar(value) {
    print('_privateVar setter called');
  }
}

class C extends A with B {}

This happens with both the new and old mixin syntax.

This does not happen:

  • in dart2js
  • when the field is public
  • when the setter overrides occurs via a subclass

Reproducible in Dart SDK 2.2.0/2.2.1-dev.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dev-compiler

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions