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

Side by Side Diff: tests/compiler/dart2js_extra/consistent_index_error_string_test.dart

Issue 1180713003: Better messages for optimized index errors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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) 2015, 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 import "dart:typed_data";
7
8 // Test that optimized indexing and slow path indexing produce the same error.
9
10 @NoInline()
11 @AssumeDynamic()
12 confuse(x) => x;
13
14 class TooHigh {
15 static load1() {
16 var a = confuse(true) ? 'AB' : 'ABCDE';
17 try {
18 return confuse(a)[3]; // dynamic receiver for indexer.
19 } catch (e) {
20 return e;
21 }
22 Expect.fail('unreached');
23 }
24
25 static load2() {
26 try {
27 confuse(load2x)(3);
28 } catch (e) {
29 return e;
30 }
31 Expect.fail('unreached');
32 }
33 static load2x(i) {
34 var a = confuse(true) ? 'AB' : 'ABCDE';
35 return a[i]; // 'a' is String of unknown length.
36 }
37
38 static test() {
39 var e1 = load1();
40 var e2 = load2();
41 print(" A: '$e1'\n B: '$e2'");
42 Expect.equals('$e1', '$e2');
43 }
44 }
45
46 class Negative {
47 static load1() {
48 var a = confuse(true) ? 'AB' : 'ABCDE';
49 try {
50 return confuse(a)[-3]; // dynamic receiver for indexer.
51 } catch (e) {
52 return e;
53 }
54 Expect.fail('unreached');
55 }
56
57 static load2() {
58 try {
59 confuse(load2x)(-3);
60 } catch (e) {
61 return e;
62 }
63 Expect.fail('unreached');
64 }
65 static load2x(i) {
66 var a = confuse(true) ? 'AB' : 'ABCDE';
67 return a[i]; // 'a' is String of unknown length.
68 }
69
70 static test() {
71 var e1 = load1();
72 var e2 = load2();
73 print(" A: '$e1'\n B: '$e2'");
74 Expect.equals('$e1', '$e2');
75 }
76 }
77
78 class Empty {
79 static load1() {
80 var a = confuse(true) ? '' : 'ABCDE';
81 try {
82 return confuse(a)[-3]; // dynamic receiver for indexer.
83 } catch (e) {
84 return e;
85 }
86 Expect.fail('unreached');
87 }
88
89 static load2() {
90 try {
91 confuse(load2x)(-3);
92 } catch (e) {
93 return e;
94 }
95 Expect.fail('unreached');
96 }
97 static load2x(i) {
98 var a = confuse(true) ? '' : 'ABCDE';
99 return a[i]; // 'a' is String of unknown length.
100 }
101
102 static test() {
103 var e1 = load1();
104 var e2 = load2();
105 print(" A: '$e1'\n B: '$e2'");
106 Expect.equals('$e1', '$e2');
107 }
108 }
109
110 class BadType {
111 static load1() {
112 var a = confuse(true) ? 'AB' : 'ABCDE';
113 try {
114 return confuse(a)['a']; // dynamic receiver for indexer.
115 } catch (e) {
116 return e;
117 }
118 Expect.fail('unreached');
119 }
120
121 static load2() {
122 try {
123 confuse(load2x)('a');
124 } catch (e) {
125 return e;
126 }
127 Expect.fail('unreached');
128 }
129 static load2x(i) {
130 var a = confuse(true) ? 'AB' : 'ABCDE';
131 return a[i]; // 'a' is String of unknown length.
132 }
133
134 static test() {
135 var e1 = load1();
136 var e2 = load2();
137 print(" A: '$e1'\n B: '$e2'");
138 Expect.equals('$e1', '$e2');
139 }
140 }
141
142 main() {
143 TooHigh.test();
144 Negative.test();
145 Empty.test();
146 BadType.test();
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698