dart-sdk/pkg/front_end/testcases/reorder_super.dart
Paul Berry 41170b0a15 When reordering constructor initializers, use correct types for temp vars.
In strong mode, when a call to a super-initializer is reordered, we
can use the static type of the super-initializer arguments to set the
types of the temporary variables that we use to do the reordering.
This is desirable because it might help avoid unnecessary casts.

In non-strong mode, we use `dynamic` for the temporary variables, to
replicate Dart 1.0 behavior.

R=scheglov@google.com

Review-Url: https://codereview.chromium.org/2993193002 .
2017-08-07 13:55:40 -07:00

40 lines
806 B
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This test verifies that super calls get reordered properly. It exercises the
// case where the arguments to super have a type other than `dynamic`.
String events = '';
int f(x) {
events += 'f($x)\n';
return 0;
}
String g(x) {
events += 'g($x)\n';
return 'foo';
}
class B {
num x;
String y;
B(this.x, this.y) {
events += 'super($x, $y)\n';
}
}
class C extends B {
final z;
C()
: super(f(1), g(2)),
z = f(3);
}
main() {
new C();
if (events != 'f(1)\ng(2)\nf(3)\nsuper(0, foo)\n') {
throw 'Unexpected sequence of events: $events';
}
}