Skip to content

[dartdevc] DDK does not properly dispatch to getters that shadow local const variables in const classes. #38455

@Markzipan

Description

@Markzipan

Snippet:

class EnumClass {
  final String name;
  const EnumClass(this.name);
  String toString() => name;
}

class Foo extends EnumClass {
  static const Foo VALUE = Foo._('HIDDEN');
  String get name => DateTime.now().toString();
  const Foo._(String name) : super(name);
}

main() {
  print(Foo.VALUE.name);
}

prints 'HIDDEN' in DDK but the current date in every other backend.

This is due to the way DDK generates constant objects. The constant field shadows the prototype's getter indirection. E.g.:

dart.defineLazy(CT, {
  get C0() {
    return C0 = dart.const({
      __proto__: pb.Foo.prototype,
      name: "HIDDEN"
    });
  }
});

Related issue: #37839

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dev-compiler-kernel-blockerIssues that block deprecation of analyzer DDCweb-dev-compiler

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions