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

Unified Diff: lib/src/info.dart

Issue 1056183002: Better error messages (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/codegen/reify_coercions.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/info.dart
diff --git a/lib/src/info.dart b/lib/src/info.dart
index a925bbd2939a127fae1c16dc4a4166292f412216..caccaaf26a4431bf91d0c9768e6919099532290b 100644
--- a/lib/src/info.dart
+++ b/lib/src/info.dart
@@ -212,7 +212,8 @@ abstract class DownCast extends Conversion {
'to cast to type $convertedType';
// Factory to create correct DownCast variant.
- static StaticInfo create(TypeRules rules, Expression expression, Cast cast) {
+ static StaticInfo create(TypeRules rules, Expression expression, Cast cast,
+ {String reason}) {
final fromT = cast.fromType;
final toT = cast.toType;
@@ -224,7 +225,8 @@ abstract class DownCast extends Conversion {
// Handle null call specially.
if (expression is NullLiteral) {
if (rules.isNonNullableType(toT)) {
- return new StaticTypeError(rules, expression, toT);
+ reason = "null is invalid as a $toT";
+ return new StaticTypeError(rules, expression, toT, reason: reason);
} else {
// We should only get here if some coercion is required.
assert(rules.maybeNonNullableType(toT));
@@ -237,7 +239,7 @@ abstract class DownCast extends Conversion {
if (expression is Literal) {
// fromT should be an exact type - this will almost certainly fail at
// runtime.
- return new StaticTypeError(rules, expression, toT);
+ return new StaticTypeError(rules, expression, toT, reason: reason);
}
if (expression is FunctionExpression) {
// fromT should be an exact type - this will almost certainly fail at
@@ -247,7 +249,7 @@ abstract class DownCast extends Conversion {
if (expression is InstanceCreationExpression) {
// fromT should be an exact type - this will almost certainly fail at
// runtime.
- return new StaticTypeError(rules, expression, toT);
+ return new StaticTypeError(rules, expression, toT, reason: reason);
}
// Composite cast: these are more likely to fail.
@@ -496,13 +498,16 @@ abstract class StaticError extends StaticInfo {
class StaticTypeError extends StaticError {
final DartType baseType;
final DartType expectedType;
+ String reason = null;
- StaticTypeError(TypeRules rules, Expression expression, this.expectedType)
+ StaticTypeError(TypeRules rules, Expression expression, this.expectedType,
+ {this.reason})
: baseType = rules.getStaticType(expression),
super(expression);
String get message =>
- 'Type check failed: $node ($baseType) is not of type $expectedType';
+ 'Type check failed: $node ($baseType) is not of type $expectedType' +
+ ((reason == null) ? '' : ' because $reason');
}
class InvalidVariableDeclaration extends StaticError {
« no previous file with comments | « lib/src/codegen/reify_coercions.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698