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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.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/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index 8e348952d2cce0218991f9bdccd10642ca2b5e47..d5860656129c8585d0f4041ca167e264d326bc4a 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -1899,6 +1899,37 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertErrors(libraryResult.getErrors());
}
+ /**
+ * It is a static warning if the return type of the user-declared operator negate is explicitly
+ * declared and not a numerical type.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3224
+ */
+ public void test_negateOperatorType() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " num operator negate() {}",
+ "}",
+ "class B {",
+ " int operator negate() {}",
+ "}",
+ "class C {",
+ " double operator negate() {}",
+ "}",
+ "class D {",
+ " String operator negate() {}",
+ "}",
+ "class E {",
+ " Object operator negate() {}",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(TypeErrorCode.OPERATOR_NEGATE_NUM_RETURN_TYPE, 12, 3, 6),
+ errEx(TypeErrorCode.OPERATOR_NEGATE_NUM_RETURN_TYPE, 15, 3, 6));
+ }
+
private AnalyzeLibraryResult analyzeLibrary(String... lines) throws Exception {
return analyzeLibrary(getName(), makeCode(lines));
}

Powered by Google App Engine
This is Rietveld 408576698