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

Unified Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java

Issue 9860051: Dartc erroneously reported a compile-time error on a const class with a non-final static field (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added documentation to test case Created 8 years, 9 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/resolver/ResolverTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
index 3fe05ce098568d7126dbe8dbfc54655f74193604..263a8471349e544438ec692698ddf41efd688e2a 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java
@@ -13,6 +13,8 @@ import com.google.dart.compiler.type.InterfaceType;
import com.google.dart.compiler.type.Type;
import com.google.dart.compiler.type.Types;
+import static com.google.dart.compiler.common.ErrorExpectation.errEx;
+
import junit.framework.Assert;
import java.util.List;
@@ -1070,4 +1072,42 @@ public class ResolverTest extends ResolverTestCase {
"}"),
ResolverErrorCode.DUPLICATE_TYPE_VARIABLE_WARNING);
}
+
+ public void testConstClass() {
+ resolveAndTest(Joiner.on("\n").join(
+ "class Object {}",
+ "interface int {}",
+ "class GoodBase {",
+ " const GoodBase() : foo = 1;",
+ " final foo;",
+ "}",
+ "class BadBase {",
+ " BadBase() {}",
+ " var foo;",
+ "}", // line 10
+ "class Bad {",
+ " const Bad() : bar = 1;",
+ " var bar;", // error: non-final field in const class
+ "}",
+ "class BadSub1 extends BadBase {",
+ " const BadSub1() : super(), bar = 1;", // error2: inherits non-final field, super !const
+ " final bar;",
+ "}",
+ "class BadSub2 extends GoodBase {",
+ " const BadSub2() : super(), bar = 1;", // line 20
+ " var bar;", // error: non-final field in constant class
+ "}",
+ "class GoodSub1 extends GoodBase {",
+ " const GoodSub1() : super(), bar = 1;",
+ " final bar;",
+ "}",
+ "class GoodSub2 extends GoodBase {",
+ " const GoodSub2() : super();",
+ " static int bar;", // OK, non-final but it is static
+ "}"),
+ errEx(ResolverErrorCode.CONST_CLASS_WITH_NONFINAL_FIELDS, 13, 7, 3),
+ errEx(ResolverErrorCode.CONST_CONSTRUCTOR_MUST_CALL_CONST_SUPER, 16, 9, 7),
+ errEx(ResolverErrorCode.CONST_CLASS_WITH_INHERITED_NONFINAL_FIELDS, 9, 7, 3),
+ errEx(ResolverErrorCode.CONST_CLASS_WITH_NONFINAL_FIELDS, 21, 7, 3));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698