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

Unified Diff: pkg/analyzer/lib/src/task/strong/checker.dart

Issue 2482573002: fix #27764, split STATIC_TYPE_ERROR into more detailed ones (Closed)
Patch Set: format Created 4 years, 1 month 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 | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/strong/checker.dart
diff --git a/pkg/analyzer/lib/src/task/strong/checker.dart b/pkg/analyzer/lib/src/task/strong/checker.dart
index b32ff6e515e26aa2b913ea66939586deaee448f5..e8c80c0a34fab332847a03a04450f6ee9b756a3e 100644
--- a/pkg/analyzer/lib/src/task/strong/checker.dart
+++ b/pkg/analyzer/lib/src/task/strong/checker.dart
@@ -1051,10 +1051,25 @@ class CodeChecker extends RecursiveAstVisitor {
assert(rules.isSubtypeOf(to, from));
// Inference "casts":
- if (expr is Literal || expr is FunctionExpression) {
+ if (expr is Literal) {
// fromT should be an exact type - this will almost certainly fail at
// runtime.
- _recordMessage(expr, StrongModeCode.STATIC_TYPE_ERROR, [expr, from, to]);
+ if (expr is ListLiteral) {
+ _recordMessage(
+ expr, StrongModeCode.INVALID_CAST_LITERAL_LIST, [from, to]);
+ } else if (expr is MapLiteral) {
+ _recordMessage(
+ expr, StrongModeCode.INVALID_CAST_LITERAL_MAP, [from, to]);
+ } else {
+ _recordMessage(
+ expr, StrongModeCode.INVALID_CAST_LITERAL, [expr, from, to]);
+ }
+ return;
+ }
+
+ if (expr is FunctionExpression) {
+ _recordMessage(
+ expr, StrongModeCode.INVALID_CAST_FUNCTION_EXPR, [from, to]);
return;
}
@@ -1063,15 +1078,19 @@ class CodeChecker extends RecursiveAstVisitor {
if (e == null || !e.isFactory) {
// fromT should be an exact type - this will almost certainly fail at
// runtime.
-
- _recordMessage(
- expr, StrongModeCode.STATIC_TYPE_ERROR, [expr, from, to]);
+ _recordMessage(expr, StrongModeCode.INVALID_CAST_NEW_EXPR, [from, to]);
return;
}
}
if (isKnownFunction(expr)) {
- _recordMessage(expr, StrongModeCode.STATIC_TYPE_ERROR, [expr, from, to]);
+ Element e = _getKnownElement(expr);
+ _recordMessage(
+ expr,
+ e is MethodElement
+ ? StrongModeCode.INVALID_CAST_METHOD
+ : StrongModeCode.INVALID_CAST_FUNCTION,
+ [e.name, from, to]);
return;
}
« no previous file with comments | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698