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

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

Issue 10830145: Issue 3847. Allow non-constant instance variable initializers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use different ErrorCode for using instance fields in instance field initializers Created 8 years, 5 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/CompileTimeConstantTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java
index a10c36edfb7132c0b57254379b5ae2ffc2e6246c..1a7bf906a25be265b73fad1cf46812fb2171248c 100644
--- a/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java
+++ b/compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java
@@ -46,6 +46,47 @@ public class CompileTimeConstantTest extends ResolverTestCase {
}
/**
+ * This is allowed in "Spec 0.11".
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3847
+ */
+ public void test_instanceVariable_nonConstInitializer() {
+ resolveAndTestCtConstExpectErrors(Joiner.on("\n").join(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class Object {}",
+ "class A {",
+ " var f = new Object();",
+ "}"));
+ }
+
+ /**
+ * We can not reference "this" directly or indirectly as reference to other fields.
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3847
+ */
+ public void test_instanceVariable_nonConstInitializer_cannotReferenceThis() {
+ resolveAndTestCtConstExpectErrors(
+ Joiner.on("\n").join(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class Object {}",
+ "class Val {",
+ " Val(var o) {}",
+ "}",
+ "class A {",
+ " var f1 = new Val(1);",
+ " var f2 = this;",
+ " var f3 = new Val(f1);",
+ "}",
+ "class B extends A {",
+ " var f2 = new Val(f3);",
+ "}",
+ ""),
+ errEx(ResolverErrorCode.CANNOT_USE_THIS_IN_INSTANCE_FIELD_INITIALIZER, 8, 11, 4),
+ errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INITIALIZER, 9, 19, 2),
+ errEx(ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INITIALIZER, 12, 19, 2));
+ }
+
+ /**
* <p>
* http://code.google.com/p/dart/issues/detail?id=1655
*/
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698