dart-archive / kernel

Dart IR (Intermediate Representation) -- moved to dart-lang/sdk
BSD 3-Clause "New" or "Revised" License
20 stars 3 forks source link

Bug in generation of constructor initializers #13

Closed mkustermann closed 8 years ago

mkustermann commented 8 years ago

This test should behave differently (from tests/co19/src/Language/Expressions/Instance_Creation/New/execution_t09.dart):

import 'tests/co19/src/Utils/expect.dart';

var evalOrder = '';

log(var s) {
  evalOrder = '$evalOrder$s';
}

class A {
  A() : this.a2();
  A.a2() {
    log("2");
  }
}

class B extends A {
  var v;

  B.b2() : super(), v = log("1") {
    log("3");
  }
}

main() {
  new B.b2();
  Expect.equals("123", evalOrder, "Super constructor was not executed properly!");
}

This get compiled to:

  class A extends core::Object {
    constructor •() → void
      : this test::A::a2();
    constructor a2() → void {
      test::log("2");
    }
  }
  class B extends test::A {
    field dynamic v;
    constructor b2() → void
      : super test::A::•(), test::B::v = test::log("1") {
      test::log("3");
    }
  }
  static field dynamic evalOrder = "";
  static method log(dynamic s) → dynamic {
    test::evalOrder = "${test::evalOrder}${s}";
  }
  static method main() → dynamic {
    new test::B::b2();
    Exp::Expect::equals("123", test::evalOrder, "Super constructor was not executed properly!");
  }

It is probably supposed to re-order the initializers

from

 B.b2() : super(), v = log("1") {
    log("3");
  }

to

 B.b2() : v = log("1"), super() {
    log("3");
  }

/cc @peter-ahe-google

asgerf commented 8 years ago

I believe this has been fixed.