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

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

Issue 11087018: Issue 5652. Suggest to use effective integer division ~/, warning and Quick Fix. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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: 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 28ebdb486e6366ebd4334f13acbc513117972c64..d198622ef75e976594156ed90c4f57cfb3283dee 100644
--- a/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java
@@ -1465,9 +1465,30 @@ public class TypeAnalyzer implements DartCompilationPhase {
FunctionType methodType = getMethodType(receiver, member, name, nameNode);
Type returnType = checkInvocation(node, nameNode, name, methodType);
returnType = ExternalTypeAnalyzers.resolve(types, node, element, returnType);
+ warningEffectiveIntegerDivision(node, element);
return returnType;
}
+ /**
+ * http://code.google.com/p/dart/issues/detail?id=5652
+ */
+ private void warningEffectiveIntegerDivision(DartMethodInvocation node, Element element) {
+ if (element != null && element.getName().equals("toInt")
+ && element.getEnclosingElement() != null
+ && element.getEnclosingElement().getName().equals("num")) {
+ DartExpression target = node.getTarget();
+ while (target instanceof DartParenthesizedExpression) {
+ target = ((DartParenthesizedExpression) target).getExpression();
+ }
+ if (target instanceof DartBinaryExpression) {
+ DartBinaryExpression binary = (DartBinaryExpression) target;
+ if (binary.getOperator() == Token.DIV) {
+ typeError(node, TypeErrorCode.USE_INTEGER_DIVISION);
+ }
+ }
+ }
+ }
+
private void checkIllegalPrivateAccess(DartNode diagnosticNode, Element element, String name) {
if (DartIdentifier.isPrivateName(name)) {
if (element != null) {

Powered by Google App Engine
This is Rietveld 408576698