Skip to content

CFE constant initializers sometimes have duplicate optional argument keys. #37839

@Markzipan

Description

@Markzipan

For the following snippet:

const a = A();

class A extends Z<int> {
  const A() : super();

  @override
  final int defaultValue = 100;
}

class Z<T> {
  final T defaultValue;
  const Z({this.defaultValue});
}

main() {
  print(a.defaultValue);
}

the CFE generates:

main = sta::main;
library from "org-dartlang-app:/static1.dart" as sta {

  class A extends sta::Z<core::int*> {
    @#C1
    final field core::int* defaultValue = 100;
    const constructor •() → sta::A*
      : super sta::Z::•()
      ;
  }
  class Z<T extends core::Object* = dynamic> extends core::Object {
    final field sta::Z::T* defaultValue;
    const constructor •({sta::Z::T* defaultValue = #C2}) → sta::Z<sta::Z::T*>*
      : sta::Z::defaultValue = defaultValue, super core::Object::•()
      ;
  }
  static const field sta::A* a = #C4;
  static method main() → dynamic {
    core::print(sta::a.{sta::A::defaultValue});
  }
}
constants  {
  #C1 = core::_Override {}
  #C2 = null
  #C3 = 100
  #C4 = sta::A {defaultValue:#C3, defaultValue:#C2}
}

The VM and DDC print 100, but DDK prints null because it emits both defaultValue arguments from left-to-right without any de-duping logic.

Are default parameters supposed to be de-duped in the CFE, or is there some sort of prescribed evaluation order (right-to-left here)? This pattern is used a bit in google3.

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-dev-compiler

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions