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

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

Issue 9289029: Added runtime type checking to the elements of list and map literals in dartc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks 4 // VMOptions=--enable_type_checks
5 // 5 //
6 // Dart test program testing type checks in list literals. 6 // Dart test program testing type checks in list literals.
7 7
8 class ListLiteral4Test<T> { 8 class ListLiteral4Test<T> {
9 test() { 9 test() {
10 int result = 0; 10 int result = 0;
11 try { 11 try {
12 var m = <String>[0, 1]; // 0 is not a String. 12 var m = <String>[0, 1]; // 0 is not a String.
13 } catch (TypeError error) { 13 } catch (TypeError error) {
14 result += 1; 14 result += 1;
15 } 15 }
16 try { 16 try {
17 var m = <int>[0, 1]; 17 var m = <int>[0, 1];
18 m["0"] = 1; // "0" is not an int. 18 m["0"] = 1; // "0" is not an int.
19 } catch (TypeError error) { 19 } catch (TypeError error) {
20 result += 10; 20 result += 10;
21 } 21 }
22 try { 22 try {
23 var m = <T>{"a": "b"}; // "b" is not an int. 23 var m = <T>["a", "b"]; // "b" is not an int.
zundel 2012/01/25 23:41:22 My guess is this was some kind of cut and paste er
24 } catch (TypeError error) { 24 } catch (TypeError error) {
25 result += 100; 25 result += 100;
26 } 26 }
27 try { 27 try {
28 var m = <T>[0, 1]; // OK. 28 var m = <T>[0, 1]; // OK.
29 } catch (TypeError error) { 29 } catch (TypeError error) {
30 result += 1000; 30 result += 1000;
31 } 31 }
32 try { 32 try {
33 var m = <T>[0, 1]; 33 var m = <T>[0, 1];
(...skipping 10 matching lines...) Expand all
44 return result; 44 return result;
45 } 45 }
46 } 46 }
47 47
48 main() { 48 main() {
49 var t = new ListLiteral4Test<int>(); 49 var t = new ListLiteral4Test<int>();
50 Expect.equals(110111, t.test()); 50 Expect.equals(110111, t.test());
51 } 51 }
52 52
53 53
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698