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

Unified Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 26978004: Emit a compile-time error when using doubles as switch case expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/ssa/builder.dart
diff --git a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
index af661e7c19e99ca23658aedf20eda7ed7b5a8998..a1a299a421613c94efac1bcfd59b0173eaab560b 100644
--- a/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
+++ b/sdk/lib/_internal/compiler/implementation/ssa/builder.dart
@@ -4577,28 +4577,13 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
visit(node.expression);
}
- Map<CaseMatch,Constant> buildSwitchCaseConstants(SwitchStatement node) {
+ Map<CaseMatch, Constant> buildSwitchCaseConstants(SwitchStatement node) {
Map<CaseMatch, Constant> constants = new Map<CaseMatch, Constant>();
- // First check whether all case expressions are compile-time constants,
- // and all have the same type that doesn't override operator==.
- // TODO(lrn): Move the constant resolution to the resolver, so
- // we can report an error before reaching the backend.
- DartType firstConstantType = null;
- bool failure = false;
for (SwitchCase switchCase in node.cases) {
for (Node labelOrCase in switchCase.labelsAndCases) {
if (labelOrCase is CaseMatch) {
CaseMatch match = labelOrCase;
Constant constant = getConstantForNode(match.expression);
- if (firstConstantType == null) {
- firstConstantType = constant.computeType(compiler);
- if (nonPrimitiveTypeOverridesEquals(constant)) {
- compiler.reportFatalError(
- match.expression,
- MessageKind.SWITCH_CASE_VALUE_OVERRIDES_EQUALS);
- failure = true;
- }
- }
constants[labelOrCase] = constant;
}
}
@@ -4955,35 +4940,6 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
jumpHandler.close();
}
- bool nonPrimitiveTypeOverridesEquals(Constant constant) {
- // Function values override equals. Even static ones, since
- // they inherit from [Function].
- if (constant.isFunction()) return true;
-
- // [Map] and [List] do not override equals.
- // If constant is primitive, just return false. We know
- // about the equals methods of num/String classes.
- if (!constant.isConstructedObject()) return false;
-
- ConstructedConstant constructedConstant = constant;
- DartType type = constructedConstant.type;
- assert(type != null);
- Element element = type.element;
- // If the type is not a class, we'll just assume it overrides
- // operator==. Typedefs do, since [Function] does.
- if (!element.isClass()) return true;
- ClassElement classElement = element;
- return typeOverridesObjectEquals(classElement);
- }
-
- bool typeOverridesObjectEquals(ClassElement classElement) {
- Element operatorEq =
- lookupOperator(classElement, const SourceString('=='));
- if (operatorEq == null) return false;
- // If the operator== declaration is in Object, it's not overridden.
- return (operatorEq.getEnclosingClass() != compiler.objectClass);
- }
-
Element lookupOperator(ClassElement classElement, SourceString operatorName) {
SourceString dartMethodName =
Elements.constructOperatorName(operatorName, false);

Powered by Google App Engine
This is Rietveld 408576698