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

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

Issue 10540048: Implement 'as' operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: No entries in language.status, vm and dartc already implemented 'as'. Created 8 years, 5 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 // Dart test program for constructors and initializers.
5
6 // Test 'expression as Type' casts.
7
8 class C {
9 final int foo = 42;
10 }
11
12 class D extends C {
13 final int bar = 37;
14 }
15
16 Object createC() => new C();
17 Object createD() => new D();
18 Object getNull() => null;
19 Object createList() => <int>[2];
20 Object createInt() => 87;
21 Object createString() => "a string";
22
23 main() {
24 Object oc = createC();
25 Object od = createD();
26 Object on = getNull();
27 Object ol = createList();
28 Object oi = createInt();
29 Object os = createString();
30
31 Expect.equals(42, (oc as C).foo);
32 Expect.equals(42, (od as C).foo);
33 Expect.equals(42, (od as D).foo);
34 Expect.equals(37, (od as D).bar);
35 Expect.equals(37, ((od as C) as D).bar);
36 (oc as D).foo; /// 01: runtime error
37 (on as D).toString();
38 (on as D).foo; /// 02: runtime error
39 (on as C).foo; /// 03: runtime error
40 oc.foo; /// 04: static type warning
41 od.foo; /// 05: static type warning
42 (on as Object).toString();
43 (oc as Object).toString();
44 (od as Object).toString();
45 (on as Dynamic).toString();
46 (on as Dynamic).foo; /// 07: runtime error
47 (oc as Dynamic).foo;
48 (od as Dynamic).foo;
49 (oc as Dynamic).bar; /// 08: runtime error
50 (od as Dynamic).bar;
51 C c = oc as C;
52 c = od as C;
53 c = oc;
54 D d = od as D;
55 d = oc as D; /// 10: runtime error
56 d = od;
57
58 (ol as List)[0];
59 (ol as List<int>)[0];
60 (ol as Dynamic)[0];
61 (ol as String).length; /// 12: runtime error
62 int x = (ol as List<int>)[0];
63 (ol as List<int>)[0] = (oi as int);
64
65 (os as String).length;
66 (os as Dynamic).length;
67 (oi as String).length; /// 13: runtime error
68 (os as List).length; /// 14: runtime error
69
70 (oi as int) + 2;
71 (oi as List).length; /// 15: runtime error
72 }
73
74
OLDNEW
« lib/compiler/implementation/lib/js_helper.dart ('K') | « lib/compiler/implementation/ssa/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698