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

Unified Diff: sdk/lib/_internal/compiler/implementation/typechecker.dart

Issue 21292003: Handle int/double case expression types correctly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments Created 7 years, 4 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
Index: sdk/lib/_internal/compiler/implementation/typechecker.dart
diff --git a/sdk/lib/_internal/compiler/implementation/typechecker.dart b/sdk/lib/_internal/compiler/implementation/typechecker.dart
index d9f7c5bc4240f174e74dc6582889cb91b6886239..41fc2b5959c14347f56825b95870db48a99abcca 100644
--- a/sdk/lib/_internal/compiler/implementation/typechecker.dart
+++ b/sdk/lib/_internal/compiler/implementation/typechecker.dart
@@ -1187,18 +1187,50 @@ class TypeCheckerVisitor extends Visitor<DartType> {
visitSwitchStatement(SwitchStatement node) {
// TODO(johnniwinther): Handle reachability based on reachability of
// switch cases.
- // TODO(johnniwinther): Check assignability to constants.
DartType expressionType = analyze(node.expression);
+ Map<CaseMatch, DartType> caseTypeMap =
+ new LinkedHashMap<CaseMatch, DartType>();
for (SwitchCase switchCase in node.cases) {
for (Node labelOrCase in switchCase.labelsAndCases) {
CaseMatch caseMatch = labelOrCase.asCaseMatch();
if (caseMatch == null) continue;
DartType caseType = analyze(caseMatch.expression);
+ caseTypeMap[caseMatch] = caseType;
checkAssignable(caseMatch, expressionType, caseType);
}
+
analyze(switchCase);
}
+
+ CaseMatch firstCase = null;
+ DartType firstCaseType = null;
+ bool hasReportedProblem = false;
+ caseTypeMap.forEach((CaseMatch caseMatch, DartType caseType) {
+ if (firstCaseType == null) {
+ firstCase = caseMatch;
+ firstCaseType = caseType;
+ } else {
+ if (caseType != firstCaseType) {
+ if (!hasReportedProblem) {
+ compiler.reportError(
+ node,
+ MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL,
+ {'type': firstCaseType});
+ compiler.reportInfo(
+ firstCase.expression,
+ MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
+ {'type': firstCaseType});
+ hasReportedProblem = true;
+ }
+ compiler.reportInfo(
+ caseMatch.expression,
+ MessageKind.SWITCH_CASE_TYPES_NOT_EQUAL_CASE,
+ {'type': caseType});
+ }
+ }
+ });
+
return StatementType.NOT_RETURNING;
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/builder.dart ('k') | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698