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

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

Issue 3005643002: Migrate block 115. (Closed)
Patch Set: Tweak status files. Created 3 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
« no previous file with comments | « tests/language/getter_setter_order_test.dart ('k') | tests/language/getters_setters_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
5 import "package:expect/expect.dart";
6
7 // Tests classes with getters and setters that do not have the same type.
8
9 class A {
10 int a() {
11 return 37;
12 }
13 }
14
15 class B extends A {
16 int b() {
17 return 38;
18 }
19 }
20
21 class C {}
22
23 class T1 {
24 A getterField;
25 A get field {
26 return getterField;
27 }
28
29 // OK, B is assignable to A
30 void set field(B arg) {
31 getterField = arg;
32 }
33 }
34
35 class T2 {
36 A getterField;
37 C setterField;
38 A get field {
39 return getterField;
40 }
41
42 // Type C is not assignable to A
43 void set field(C arg) { setterField = arg; } //# 01: static type warning
44 }
45
46 class T3 {
47 B getterField;
48 B get field {
49 return getterField;
50 }
51
52 // OK, A is assignable to B
53 void set field(A arg) {
54 getterField = arg;
55 }
56 }
57
58 main() {
59 T1 instance1 = new T1();
60 T2 instance2 = new T2(); //# 01: continued
61 T3 instance3 = new T3();
62
63 instance1.field = new B();
64 A resultA = instance1.field;
65 instance1.field = new A(); //# 03: dynamic type error
66 B resultB = instance1.field;
67
68 int result;
69 result = instance1.field.a();
70 Expect.equals(37, result);
71
72 // Type 'A' has no method named 'b'
73 instance1.field.b(); //# 02: static type warning
74
75 instance3.field = new B();
76 result = instance3.field.a();
77 Expect.equals(37, result);
78 result = instance3.field.b();
79 Expect.equals(38, result);
80 }
OLDNEW
« no previous file with comments | « tests/language/getter_setter_order_test.dart ('k') | tests/language/getters_setters_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698