Files
sdk/tests/language/final_field_initialization_order_test.dart
T
kasperl@google.com 2028d2fa70 Get rid of multiple assignments to final instance fields.
Thanks to Matthias for spotting this issue in the first version
of the test for final instance fields.

R=ngeoffray@google.com,hausner@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10909048

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11746 260f80e4-7a28-3924-810f-c04153c831b5
2012-09-03 06:54:16 +00:00

59 lines
1.4 KiB
Dart

// Copyright (c) 2012, 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.
// Test that initializers for final fields are evaluated in the right
// order.
int counter = 0;
class Mark {
static StringBuffer buffer;
Mark(value) {
buffer.add('$value.');
}
}
class OneField {
final a = new Mark('a');
OneField();
}
class TwoFields {
final a = new Mark('a');
final b = new Mark('b');
TwoFields();
}
class InheritOneField extends OneField {
final b = new Mark('b');
InheritOneField();
}
class MixedFields extends OneField {
final b = new Mark('b');
var c = new Mark('c');
final d = new Mark('d');
MixedFields();
MixedFields.c0() : c = new Mark('cc');
MixedFields.c1() : c = new Mark('cc'), super();
MixedFields.c2() : super(), c = new Mark('cc');
}
String run(callback) {
Mark.buffer = new StringBuffer();
callback();
return Mark.buffer.toString();
}
main() {
Expect.equals('a.', run(() => new OneField()));
Expect.equals('a.b.', run(() => new TwoFields()));
Expect.equals('b.a.', run(() => new InheritOneField()));
Expect.equals('b.c.d.a.', run(() => new MixedFields()));
Expect.equals('b.c.d.cc.a.', run(() => new MixedFields.c0()));
Expect.equals('b.c.d.cc.a.', run(() => new MixedFields.c1()));
Expect.equals('b.c.d.a.cc.', run(() => new MixedFields.c2()));
}