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

Side by Side Diff: tests/language/src/GettersSetters2Test.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
5 // Tests classes with getters and setters that do not have the same type.
6
7 class A {
8 int a() { return 37;}
9 }
10
11 class B extends A{
12 int b() { return 38; }
13 }
14
15 class C {}
16
17 class T1 {
18 A getterField;
19 A get field() { return getterField; }
20 // OK, B is assignable to A
21 void set field(B arg) { getterField = arg; }
22 }
23
24 class T2 {
25 A getterField;
26 C setterField;
27 A get field() { return getterField; }
28
29 // Type C is not assignable to A
30 void set field(C arg) { setterField = arg; } /// 01: static type warning
31 }
32
33 class T3 {
34 B getterField;
35 B get field() { return getterField; }
36 // OK, A is assignable to B
37 void set field(A arg) { getterField = arg; }
38 }
39
40
41 main() {
42 T1 instance1 = new T1();
43 T2 instance2 = new T2(); /// 01: continued
44 T3 instance3 = new T3();
45
46 instance1.field = new B();
47 A resultA = instance1.field;
48 instance1.field = new A(); /// 03: dynamic type error
49 B resultB = instance1.field;
50
51 int result;
52 result = instance1.field.a();
53 Expect.equals(37, result);
54
55 // Type 'A' has no method named 'b'
56 instance1.field.b(); /// 02: static type warning
57
58 instance3.field = new B();
59 result = instance3.field.a();
60 Expect.equals(37, result);
61 result = instance3.field.b();
62 Expect.equals(38, result);
63 }
OLDNEW
« no previous file with comments | « tests/language/src/GetterSetterInLibTest.dart ('k') | tests/language/src/GettersSettersTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698