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

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

Issue 10542008: Issue 3224. Incorrect return type of negate operator should cause a static warning (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak for message 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
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 093ad9a8590beecd5edab2dbb98b1290b90165a7..719a9b20808cc5f957f8dbd84b0c1854d81e7b12 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -1508,12 +1508,12 @@ public class TypeAnalyzer implements DartCompilationPhase {
public Type visitMethodDefinition(DartMethodDefinition node) {
MethodElement methodElement = node.getElement();
Modifiers modifiers = methodElement.getModifiers();
+ DartTypeNode returnTypeNode = node.getFunction().getReturnTypeNode();
if (modifiers.isFactory()) {
analyzeFactory(node.getName(), (ConstructorElement) methodElement);
} else if (modifiers.isSetter()) {
- DartTypeNode returnType = node.getFunction().getReturnTypeNode();
- if (returnType != null && returnType.getType() != voidType) {
- typeError(returnType, TypeErrorCode.SETTER_RETURN_TYPE, methodElement.getName());
+ if (returnTypeNode != null && returnTypeNode.getType() != voidType) {
+ typeError(returnTypeNode, TypeErrorCode.SETTER_RETURN_TYPE, methodElement.getName());
}
if (currentClass != null && methodElement.getParameters().size() > 0) {
Element parameterElement = methodElement.getParameters().get(0);
@@ -1547,6 +1547,16 @@ public class TypeAnalyzer implements DartCompilationPhase {
}
}
}
+ // operator "negate" should return numeric type
+ if (modifiers.isOperator() && methodElement.getName().equals("negate")
+ && returnTypeNode != null) {
+ Type returnType = node.getElement().getFunctionType().getReturnType();
+ if (!types.isSubtype(returnType, numType)) {
+ typeError(returnTypeNode, TypeErrorCode.OPERATOR_NEGATE_NUM_RETURN_TYPE);
+
+ }
+ }
+ // done
return typeAsVoid(node);
}

Powered by Google App Engine
This is Rietveld 408576698