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

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

Issue 11776037: Initial support for mixins in dartc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot MixinScope.java Created 7 years, 11 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 2d48ed53f2c1b3eb49af255a8a15a861fb582d0e..0da5e8d488d02a531142b3db51c078a55b0f8b14 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -718,6 +718,20 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 1, 7, 1));
}
+ public void test_warnAbstract_onConcreteClassDeclaration_hasUnimplemented_mixin() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "abstract class A {",
+ " foo();",
+ "}",
+ "class B extends Object with A {",
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 5, 7, 1));
+ }
+
/**
* There was bug that implementing setter still caused warning.
* <p>
@@ -6170,4 +6184,134 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertNotNull(expectedElement);
assertSame(nameInInvocation.getElement(), expectedElement);
}
+
+ public void test_mixin_1() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " foo() {}",
+ "}",
+ "class B extends Object with A {", // no unimplemented methods warning
+ "}",
+ "main() {",
+ " B b = new B();",
+ " A a = b;", // no 'not assignable' warning
+ "}",
+ "");
+ assertErrors(result.getErrors());
+ }
+
+ public void test_mixin_dontAddSupertypes() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " methodA() {}",
+ "}",
+ "class B extends A {",
+ " methodB() {}",
+ "}",
+ "class C extends Object with B {",
+ "}",
+ "main() {",
+ " C c = new C();",
+ " A a = c;", // 'not assignable' warning - mixing is only "B" content
+ " B b = c;", // OK
+ " c.methodB();", // OK
+ " c.methodA();", // 'no such member' warning - mixing is only "B" content
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 12, 9, 1),
+ errEx(TypeErrorCode.INTERFACE_HAS_NO_METHOD_NAMED, 15, 5, 7));
+ }
+
+ public void test_mixin_dontAddSupertypes2() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "abstract class A {",
+ " methodA();",
+ "}",
+ "abstract class B implements A {",
+ " methodB() {}",
+ "}",
+ "class C extends Object with B {", // no unimplemented methods warning
+ "}",
+ "main() {",
+ " C c = new C();",
+ " A a = c;", // 'not assignable' warning - mixing is only "B" content
+ " B b = c;", // OK
+ " c.methodB();", // OK
+ " c.methodA();", // 'no such member' warning - mixing is only "B" content
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.TYPE_NOT_ASSIGNMENT_COMPATIBLE, 12, 9, 1),
+ errEx(TypeErrorCode.INTERFACE_HAS_NO_METHOD_NAMED, 15, 5, 7));
+ }
+
+ public void test_mixin_dontAddSupertypes3() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " foo() {}",
+ "}",
+ "class B extends A {",
+ "}",
+ "abstract class C {",
+ " foo();",
+ "}",
+ "class D extends C with B {", // "foo" is not implemented, because NOT inherited from A
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.CONTRETE_CLASS_WITH_UNIMPLEMENTED_MEMBERS, 10, 7, 1));
+ }
+
+ public void test_mixin_dontLookSupertype_getter() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " get fA => 42;",
+ "}",
+ "class B extends A {",
+ " get fB => 42;",
+ "}",
+ "class C extends Object with B {",
+ "}",
+ "main() {",
+ " C c = new C();",
+ " print(c.fB);",
+ " print(c.fA);",
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.NOT_A_MEMBER_OF, 13, 11, 2));
+ }
+
+ public void test_mixin_dontLookSupertype_setter() throws Exception {
+ AnalyzeLibraryResult result = analyzeLibrary(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " set fA(x) {}",
+ "}",
+ "class B extends A {",
+ " set fB(x) {}",
+ "}",
+ "class C extends Object with B {",
+ "}",
+ "main() {",
+ " C c = new C();",
+ " c.fB = 1;",
+ " c.fA = 2;",
+ "}",
+ "");
+ assertErrors(
+ result.getErrors(),
+ errEx(TypeErrorCode.NOT_A_MEMBER_OF, 13, 5, 2));
+ }
+
}

Powered by Google App Engine
This is Rietveld 408576698