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

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

Issue 10909048: Get rid of multiple assignments to final instance fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Test that initializers for final fields are evaluated in the right 5 // Test that initializers for final fields are evaluated in the right
6 // order. 6 // order.
7 7
8 int counter = 0; 8 int counter = 0;
9 9
10 class Mark { 10 class Mark {
11 static StringBuffer buffer; 11 static StringBuffer buffer;
12 Mark(value) { 12 Mark(value) {
13 buffer.add('$value.'); 13 buffer.add('$value.');
14 } 14 }
15 } 15 }
16 16
17 class OneField { 17 class OneField {
18 final a = new Mark('a'); 18 final a = new Mark('a');
19
20 OneField(); 19 OneField();
21
22 OneField.init() : a = new Mark('ai');
23 } 20 }
24 21
25 class TwoFields { 22 class TwoFields {
23 final a = new Mark('a');
26 final b = new Mark('b'); 24 final b = new Mark('b');
27 final a = new Mark('a');
28
29 TwoFields(); 25 TwoFields();
30
31 TwoFields.initA() : a = new Mark('ai');
32
33 TwoFields.initB() : b = new Mark('bi');
34
35 TwoFields.initBoth() : a = new Mark('ai'), b = new Mark('bi');
36 } 26 }
37 27
38 class InheritOneField extends OneField { 28 class InheritOneField extends OneField {
39 final b = new Mark('b'); 29 final b = new Mark('b');
30 InheritOneField();
31 }
40 32
41 InheritOneField() : super(); 33 class MixedFields extends OneField {
42 34 final b = new Mark('b');
43 InheritOneField.init() : b = new Mark('bi'), super(); 35 var c = new Mark('c');
44 36 final d = new Mark('d');
45 InheritOneField.superWithInit() : super.init(); 37 MixedFields();
46 38 MixedFields.c0() : c = new Mark('cc');
47 InheritOneField.initWithSuperInit() : b = new Mark('bi'), super.init(); 39 MixedFields.c1() : c = new Mark('cc'), super();
48 40 MixedFields.c2() : super(), c = new Mark('cc');
49 InheritOneField.initWithSuperInit2() : super.init(), b = new Mark('bi');
50 } 41 }
51 42
52 String run(callback) { 43 String run(callback) {
53 Mark.buffer = new StringBuffer(); 44 Mark.buffer = new StringBuffer();
54 callback(); 45 callback();
55 return Mark.buffer.toString(); 46 return Mark.buffer.toString();
56 } 47 }
57 48
58 main() { 49 main() {
59 Expect.equals('a.', run(() => new OneField())); 50 Expect.equals('a.', run(() => new OneField()));
60 Expect.equals('a.ai.', run(() => new OneField.init())); 51 Expect.equals('a.b.', run(() => new TwoFields()));
52 Expect.equals('b.a.', run(() => new InheritOneField()));
61 53
62 Expect.equals('b.a.', run(() => new TwoFields())); 54 Expect.equals('b.c.d.a.', run(() => new MixedFields()));
63 Expect.equals('b.a.ai.', run(() => new TwoFields.initA())); 55 Expect.equals('b.c.d.cc.a.', run(() => new MixedFields.c0()));
64 Expect.equals('b.a.bi.', run(() => new TwoFields.initB())); 56 Expect.equals('b.c.d.cc.a.', run(() => new MixedFields.c1()));
65 Expect.equals('b.a.ai.bi.', run(() => new TwoFields.initBoth())); 57 Expect.equals('b.c.d.a.cc.', run(() => new MixedFields.c2()));
66
67 Expect.equals('b.a.', run(() =>
68 new InheritOneField()));
69 Expect.equals('b.bi.a.', run(() =>
70 new InheritOneField.init()));
71 Expect.equals('b.a.ai.', run(() =>
72 new InheritOneField.superWithInit()));
73 Expect.equals('b.bi.a.ai.', run(() =>
74 new InheritOneField.initWithSuperInit()));
75 Expect.equals('b.a.ai.bi.', run(() =>
76 new InheritOneField.initWithSuperInit2()));
77 } 58 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698