Skip to content

Duplicate field initializers: compile error expected but doesn't occur #921

Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


Ran this on our latest VM build, no compile error.

Spec ch. 7.5.1 says: Let k be a generative constructor. [...] It is a compile-time error if more than one initializer corresponding to a given instance variable appears in k's initializer list.

However, in the following example:
class C {
  C() : x = 1, y = 2, this.x = 3;
  var x;
  var y;
}
main() {
  try {
    C c = new C();
    print(c.x);
  } catch(var x) {}
}

no compile-time error occurs and both initializers are executed, which is evident after print().

other constructor variations:
C() : x = 1, y = 2, x = 3;
C(x, y) : this.x = x, this.x = y;
demonstrate the same behaviour

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions