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

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

Issue 11549014: Issue 7278. Report static warnings for redirecting factory constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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/type/TypeAnalyzer.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 910e9d1e39c86abb4c1ee7cc19bc972a245dd105..42e400aa8c2b421f782123b3067be38eeb42b735 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -5041,7 +5041,7 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_CYCLE, 6, 11, 7),
errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_CYCLE, 9, 11, 7));
}
-
+
public void test_redirectingFactoryConstructor_notConst_fromConst() throws Exception {
AnalyzeLibraryResult libraryResult = analyzeLibrary(
"// filler filler filler filler filler filler filler filler filler filler",
@@ -5058,6 +5058,78 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
errEx(ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_CONST, 7, 29, 5));
}
+ public void test_redirectingFactoryConstructor_shouldBeSubType() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " A() {}",
+ " A.named(p0) {}",
+ "}",
+ "",
+ "class B {",
+ " factory B.foo(p0) = A;",
+ " factory B.bar() = A.named;",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(TypeErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_SUBTYPE, 8, 23, 1),
+ errEx(TypeErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_BE_SUBTYPE, 9, 23, 5));
+ }
+
+ public void test_redirectingFactoryConstructor_shouldBeSubType2() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A<T> {",
+ " A.named(T t) {}",
+ "}",
+ "",
+ "class B<T> {",
+ " factory B.foo(T t) = A<T>.named;",
+ "}",
+ "class B2<T, V> {",
+ " factory B2.foo(V v) = A<V>.named;",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ }
+
+ public void test_redirectingFactoryConstructor_shouldBeSubType3() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A<T> {",
+ " A(A<T> p) {}",
+ "}",
+ "",
+ "class B<T> {",
+ " factory B.foo(A<T> p) = A;",
+ "}",
+ "");
+ assertErrors(libraryResult.getErrors());
+ }
+
+ public void test_redirectingFactoryConstructor_notSubType_typeParameterBounds() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A1<T extends String> {",
+ " A1() {}",
+ "}",
+ "class A2<T> {",
+ " A2() {}",
+ "}",
+ "",
+ "class B {",
+ " factory B.name1() = A1<String>;",
+ " factory B.name2() = A1<int>;",
+ " factory B.name3() = A2<String>;",
+ " factory B.name4() = A2<int>;",
+ "}",
+ "");
+ assertErrors(
+ libraryResult.getErrors(),
+ errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 11, 26, 3));
+ }
+
/**
* <p>
* http://code.google.com/p/dart/issues/detail?id=4778
« no previous file with comments | « compiler/java/com/google/dart/compiler/type/TypeAnalyzer.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698