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

Side by Side Diff: pkg/kernel/testcases/interpreter/object_initializers_test.dart

Issue 2985883002: Add support for field initialization in objects (Closed)
Patch Set: Fix too long line Created 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2017, 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
5 library object_initializers_test;
6
7 /// Simple program creating an object with field initializers.
8 void main() {
9 var a = new A('foo1', 'foo2');
10 print(a.foo1);
11 print(a.foo2);
12
13 var b = new B(fieldInitializer(0, 'foo1'), fieldInitializer(0, 'foo2'));
14 print(b.foo1);
15 print(b.foo2);
16 print(b.foo3);
17 }
18
19 class A {
20 String foo1;
21 String foo2;
22
23 A(String foo1, String foo2)
24 : foo1 = foo1,
25 foo2 = foo2;
26 }
27
28 class B {
29 String foo1 = fieldInitializer(1, 'foo1');
30 String foo2 = fieldInitializer(1, 'foo2');
31 String foo3 = fieldInitializer(1, 'foo3');
32
33 B(this.foo1, this.foo2) : foo3 = foo2;
34 }
35
36 String fieldInitializer(int f, String s) {
37 print('$s: $f');
38 return '$s: $f';
39 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698