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

Side by Side Diff: sdk/lib/core/errors.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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 4
5 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * Error objects thrown in the case of a program failure. 8 * Error objects thrown in the case of a program failure.
9 * 9 *
10 * An `Error` object represents a program failure that the programmer 10 * An `Error` object represents a program failure that the programmer
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 * 275 *
276 * An indexable object is one that has a `length` and a and index-operator 276 * An indexable object is one that has a `length` and a and index-operator
277 * `[]` that accepts an index if `0 <= index < length`. 277 * `[]` that accepts an index if `0 <= index < length`.
278 * 278 *
279 * If [length] is provided, it is used as the length of the indexable object, 279 * If [length] is provided, it is used as the length of the indexable object,
280 * otherwise the length is found as `indexable.length`. 280 * otherwise the length is found as `indexable.length`.
281 */ 281 */
282 static void checkValidIndex(int index, var indexable, 282 static void checkValidIndex(int index, var indexable,
283 [String name, int length, String message]) { 283 [String name, int length, String message]) {
284 if (length == null) length = indexable.length; 284 if (length == null) length = indexable.length;
285 if (index < 0 || index >= length) { 285 // Comparing with `0` as receiver produces better dart2js type inference.
286 if (0 > index || index >= length) {
286 if (name == null) name = "index"; 287 if (name == null) name = "index";
287 throw new RangeError.index(index, indexable, name, message, length); 288 throw new RangeError.index(index, indexable, name, message, length);
288 } 289 }
289 } 290 }
290 291
291 /** 292 /**
292 * Check that a range represents a slice of an indexable object. 293 * Check that a range represents a slice of an indexable object.
293 * 294 *
294 * Throws if the range is not valid for an indexable object with 295 * Throws if the range is not valid for an indexable object with
295 * the given [length]. 296 * the given [length].
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 * the first time it is read. If evaluating the initializer expression causes 562 * the first time it is read. If evaluating the initializer expression causes
562 * another read of the variable, this error is thrown. 563 * another read of the variable, this error is thrown.
563 */ 564 */
564 class CyclicInitializationError extends Error { 565 class CyclicInitializationError extends Error {
565 final String variableName; 566 final String variableName;
566 CyclicInitializationError([this.variableName]); 567 CyclicInitializationError([this.variableName]);
567 String toString() => variableName == null 568 String toString() => variableName == null
568 ? "Reading static variable during its initialization" 569 ? "Reading static variable during its initialization"
569 : "Reading static variable '$variableName' during its initialization"; 570 : "Reading static variable '$variableName' during its initialization";
570 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698