| Index: pkg/compiler/lib/src/diagnostics/invariant.dart
|
| diff --git a/pkg/compiler/lib/src/diagnostics/invariant.dart b/pkg/compiler/lib/src/diagnostics/invariant.dart
|
| index 7ad6f3580a0070cd7febe9c6e03aac04c6817b53..34a9f3e9ffaefbc15e246ea8f466cc643906b487 100644
|
| --- a/pkg/compiler/lib/src/diagnostics/invariant.dart
|
| +++ b/pkg/compiler/lib/src/diagnostics/invariant.dart
|
| @@ -44,7 +44,7 @@ bool invariant(Spannable spannable, var condition, {var message: null}) {
|
| // information on assertion errors.
|
| if (spannable == null) {
|
| throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE,
|
| - "Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE.");
|
| + 'Spannable was null for invariant. Use CURRENT_ELEMENT_SPANNABLE.');
|
| }
|
| if (condition is Function) {
|
| condition = condition();
|
| @@ -62,4 +62,28 @@ bool invariant(Spannable spannable, var condition, {var message: null}) {
|
| return true;
|
| }
|
|
|
| +/// Throws a [SpannableAssertionFailure].
|
| +///
|
| +/// Use this method to provide better information for assertion by calling
|
| +/// [failedAt] as the second argument to an `assert` statement:
|
| +///
|
| +/// assert(condition, failedAt(position, message));
|
| +///
|
| +/// [spannable] must be non-null and will be used to provide positional
|
| +/// information in the generated error message.
|
| +bool failedAt(Spannable spannable, [var message]) {
|
| + // TODO(johnniwinther): Use [spannable] and [message] to provide better
|
| + // information on assertion errors.
|
| + if (spannable == null) {
|
| + throw new SpannableAssertionFailure(
|
| + CURRENT_ELEMENT_SPANNABLE,
|
| + 'Spannable was null for failedInvariant. '
|
| + 'Use CURRENT_ELEMENT_SPANNABLE.');
|
| + }
|
| + if (message is Function) {
|
| + message = message();
|
| + }
|
| + throw new SpannableAssertionFailure(spannable, message);
|
| +}
|
| +
|
| typedef void InternalErrorFunction(Spannable location, String message);
|
|
|