Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: tests/language/field_initialization_order_test.dart

Issue 10873033: Support non-const instance field initializers. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // Test that field initializers are evaluated in the right order.
5
6 int counter = 0;
kasperl 2012/08/24 11:50:23 Counting is fun, but when you're dealing with orde
ngeoffray 2012/08/24 13:01:41 Thanks for the suggestion. Done.
7
8 class Incr {
9 int value;
10 Incr() {
11 value = counter++;
12 }
13 }
14
15 class OneField {
16 var a = new Incr();
17
18 OneField(int expectedValue) {
19 Expect.equals(expectedValue, a.value);
20 }
21
22 OneField.init(int expectedValue) : a = new Incr() {
23 Expect.equals(expectedValue, a.value);
24 }
25 }
26
27 class TwoFields {
28 var b = new Incr();
29 var a = new Incr();
30
31 TwoFields(int expectedValueForA, int expectedValueForB) {
32 Expect.equals(expectedValueForA, a.value);
33 Expect.equals(expectedValueForB, b.value);
34 }
35
36 TwoFields.initA(int expectedValueForA, int expectedValueForB)
37 : a = new Incr() {
38 Expect.equals(expectedValueForA, a.value);
39 Expect.equals(expectedValueForB, b.value);
40 }
41
42 TwoFields.initB(int expectedValueForA, int expectedValueForB)
43 : b = new Incr() {
44 Expect.equals(expectedValueForA, a.value);
45 Expect.equals(expectedValueForB, b.value);
46 }
47
48 TwoFields.initBoth(int expectedValueForA, int expectedValueForB)
49 : a = new Incr(), b = new Incr() {
50 Expect.equals(expectedValueForA, a.value);
51 Expect.equals(expectedValueForB, b.value);
52 }
53 }
54
55 class InheritOneField extends OneField {
56 var b = new Incr();
57
58 InheritOneField(int expectedValueForA, int expectedValueForB)
59 : super(expectedValueForA) {
60 Expect.equals(expectedValueForB, b.value);
61 }
62
63 InheritOneField.init(int expectedValueForA, int expectedValueForB)
64 : b = new Incr(), super(expectedValueForA) {
65 Expect.equals(expectedValueForB, b.value);
66 }
67
68 InheritOneField.justSuper(int expectedValueForA, int expectedValueForB)
69 : super(expectedValueForA) {
70 Expect.equals(expectedValueForB, b.value);
71 }
72
73 InheritOneField.superWithInit(int expectedValueForA, int expectedValueForB)
74 : super.init(expectedValueForA) {
75 Expect.equals(expectedValueForB, b.value);
76 }
77
78 InheritOneField.initWithSuperInit(int expectedValueForA,
79 int expectedValueForB)
80 : b = new Incr(), super.init(expectedValueForA) {
81 Expect.equals(expectedValueForB, b.value);
82 }
83
84 InheritOneField.initWithSuperInit2(int expectedValueForA,
85 int expectedValueForB)
86 : super.init(expectedValueForA), b = new Incr() {
87 Expect.equals(expectedValueForB, b.value);
88 }
89 }
90
91 main() {
92 new OneField(0); counter = 0;
93 new OneField.init(1); counter = 0;
94
95 new TwoFields(1, 0); counter = 0;
96 new TwoFields.initA(2, 0); counter = 0;
97 new TwoFields.initB(1, 2); counter = 0;
98 new TwoFields.initBoth(2, 3); counter = 0;
99
100 new InheritOneField(1, 0); counter = 0;
101 new InheritOneField.init(2, 1); counter = 0;
102 new InheritOneField.justSuper(1, 0); counter = 0;
103 new InheritOneField.superWithInit(2, 0); counter = 0;
104 new InheritOneField.initWithSuperInit(3, 1); counter = 0;
105 new InheritOneField.initWithSuperInit2(2, 3); counter = 0;
106 }
OLDNEW
« lib/compiler/implementation/resolver.dart ('K') | « tests/co19/co19-dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698