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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10885031: Issue 3968. Support for redirecting factory constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1cae5a0c7edfc5adf1cc485d421f750dd336c20b..069c466f4469697f3d8b029be942f003e6e4b4aa 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -36,11 +36,13 @@ import com.google.dart.compiler.ast.DartMethodDefinition;
import com.google.dart.compiler.ast.DartNewExpression;
import com.google.dart.compiler.ast.DartNode;
import com.google.dart.compiler.ast.DartParameter;
+import com.google.dart.compiler.ast.DartTypeNode;
import com.google.dart.compiler.ast.DartUnit;
import com.google.dart.compiler.ast.DartUnqualifiedInvocation;
import com.google.dart.compiler.common.SourceInfo;
import com.google.dart.compiler.parser.ParserErrorCode;
import com.google.dart.compiler.resolver.ClassElement;
+import com.google.dart.compiler.resolver.ClassNodeElement;
import com.google.dart.compiler.resolver.Element;
import com.google.dart.compiler.resolver.ElementKind;
import com.google.dart.compiler.resolver.MethodElement;
@@ -4057,7 +4059,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
libraryResult.getErrors(),
errEx(ResolverErrorCode.CONSTRUCTOR_WITH_NAME_OF_MEMBER, 3, 3, 5));
}
-
+
/**
* <p>
* http://code.google.com/p/dart/issues/detail?id=3904
@@ -4073,6 +4075,63 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertErrors(libraryResult.getErrors());
}
+ /**
+ * TODO(scheglov)
+ * <p>
+ * http://code.google.com/p/dart/issues/detail?id=3968
+ */
+ public void test_redirectingFactoryConstructor() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " A() {}",
+ " A.named() {}",
+ "}",
+ "",
+ "class B {",
+ " factory B.foo() = A;",
+ " factory B.bar() = A.named;",
+ "}",
+ ""));
+ assertErrors(libraryResult.getErrors());
+ // prepare "class A"
+ ClassElement elementA = findNode(DartClass.class, "class A").getElement();
+ Type typeA = elementA.getType();
+ // = A;
+ {
+ DartTypeNode typeNode = findNode(DartTypeNode.class, "A;");
+ Type type = typeNode.getType();
+ assertSame(typeA, type);
+ }
+ // = A.named;
+ {
+ DartTypeNode typeNode = findNode(DartTypeNode.class, "A.named;");
+ Type type = typeNode.getType();
+ assertSame(typeA, type);
+ // .named
+ DartIdentifier nameNode = findNode(DartIdentifier.class, "named;");
+ NodeElement nameElement = nameNode.getElement();
+ assertNotNull(nameElement);
+ assertSame(elementA.lookupConstructor("named"), nameElement);
+ }
+ }
+
+ public void test_redirectingFactoryConstructor_notConst_fromConst() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " A.named() {}",
+ "}",
+ "",
+ "class B {",
+ " const factory B.bar() = A.named;",
+ "}",
+ ""));
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_CONST, 7, 29, 5));
+ }
+
private <T extends DartNode> T findNode(final Class<T> clazz, String pattern) {
final int index = testSource.indexOf(pattern);
assertTrue(index != -1);
« no previous file with comments | « compiler/java/com/google/dart/compiler/resolver/ResolverErrorCode.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698