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

Unified Diff: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java

Issue 10515018: Issue 3269. Warning when 'case' is not type compatible with 'switch' expression (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add valid case expression in test Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
index 72188ed21b731815613ae7d6e77e746a1982d1ca..f4e0299f46a8437a1db8aafef509664ce2108014 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -80,6 +80,7 @@ import com.google.dart.compiler.ast.DartStringInterpolation;
import com.google.dart.compiler.ast.DartStringLiteral;
import com.google.dart.compiler.ast.DartSuperConstructorInvocation;
import com.google.dart.compiler.ast.DartSuperExpression;
+import com.google.dart.compiler.ast.DartSwitchMember;
import com.google.dart.compiler.ast.DartSwitchStatement;
import com.google.dart.compiler.ast.DartSyntheticErrorExpression;
import com.google.dart.compiler.ast.DartSyntheticErrorIdentifier;
@@ -1813,7 +1814,20 @@ public class TypeAnalyzer implements DartCompilationPhase {
@Override
public Type visitSwitchStatement(DartSwitchStatement node) {
- return typeAsVoid(node);
+ node.visitChildren(this);
+ // analyze "expression"
+ DartExpression expression = node.getExpression();
+ Type switchType = nonVoidTypeOf(expression);
+ // check "case" expressions compatibility
+ for (DartSwitchMember switchMember : node.getMembers()) {
+ if (switchMember instanceof DartCase) {
+ DartCase caseMember = (DartCase) switchMember;
+ DartExpression caseExpr = caseMember.getExpr();
+ Type caseType = nonVoidTypeOf(caseExpr);
+ checkAssignable(caseExpr, switchType, caseType);
+ }
+ }
+ return voidType;
}
@Override
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698