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

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

Issue 10829365: Issue 4553. Any constant is valid for 'case'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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: 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 a98d7083c2fb30048f689cd5ff821ffed6896ade..1feb126ddb2d3b6b34f0f7bf6ec22697c7c6150a 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -561,7 +561,7 @@ public class TypeAnalyzer implements DartCompilationPhase {
return null;
}
Member member = itype.lookupMember(methodName);
- if (member == null) {
+ if (member == null && problemTarget != null) {
if (typeChecksForInferredTypes || !receiver.isInferred()) {
typeError(problemTarget, TypeErrorCode.INTERFACE_HAS_NO_METHOD_NAMED, receiver,
methodName);
@@ -2164,11 +2164,6 @@ public class TypeAnalyzer implements DartCompilationPhase {
continue;
}
Type caseType = nonVoidTypeOf(caseExpr);
- // should be "int" or "String"
- if (!Objects.equal(caseType, intType) && !Objects.equal(caseType, stringType)) {
- onError(caseExpr, TypeErrorCode.CASE_EXPRESSION_SHOULD_BE_INT_STRING, caseType);
- continue;
- }
// all "case expressions" should be same type
if (sameCaseType == null) {
sameCaseType = caseType;
@@ -2179,6 +2174,13 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
// compatibility of "switch expression" and "case expression" types
checkAssignable(caseExpr, switchType, caseType);
+ // should not have "operator =="
+ {
+ Member operator = lookupMember(caseType, methodNameForBinaryOperator(Token.EQ), null);
+ if (operator != null) {
+ onError(caseExpr, TypeErrorCode.CASE_EXPRESSION_TYPE_SHOULD_NOT_HAVE_EQUALS, caseType);
+ }
+ }
}
}
return voidType;

Powered by Google App Engine
This is Rietveld 408576698