From 20906e34ce14448c72f0fcf3f29b57272ad7ce3b Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 1 Nov 2012 19:29:06 +0400 Subject: [PATCH] Tests for diagnostics on this and super are moved and broken into smaller parts --- .../diagnostics/tests/QualifiedThis.kt | 42 ------------ .../tests/thisAndSuper/QualifiedThis.kt | 12 ++++ .../tests/{ => thisAndSuper}/Super.kt | 27 +------- .../tests/thisAndSuper/ambigousLabelOnThis.kt | 5 ++ .../superInExtensionFunctionCall.kt | 6 ++ .../thisAndSuper/superInToplevelFunction.kt | 5 ++ .../thisAndSuper/superIsNotAnExpression.kt | 12 ++++ .../thisAndSuper/thisInFunctionLiterals.kt | 17 +++++ .../tests/thisAndSuper/thisInNestedClasses.kt | 9 +++ .../thisAndSuper/thisInToplevelFunction.kt | 4 ++ .../checkers/JetDiagnosticsTestGenerated.java | 66 +++++++++++++++---- 11 files changed, 126 insertions(+), 79 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/QualifiedThis.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt rename compiler/testData/diagnostics/tests/{ => thisAndSuper}/Super.kt (70%) create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInNestedClasses.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.kt diff --git a/compiler/testData/diagnostics/tests/QualifiedThis.kt b/compiler/testData/diagnostics/tests/QualifiedThis.kt deleted file mode 100644 index 80c5ce0b552..00000000000 --- a/compiler/testData/diagnostics/tests/QualifiedThis.kt +++ /dev/null @@ -1,42 +0,0 @@ -// FILE: f.kt -class Dup { - fun Dup() : Unit { - this@Dup - } -} - -class A() { - fun foo() : Unit { - this@A - this@a - this - } - - val x = this@A.foo() - val y = this.foo() - val z = foo() -} - -fun foo1() : Unit { - this - this@a -} - -// FILE: f.kt -package closures - class A(val a:Int) { - - class B() { - val x = this@B : B - val y = this@A : A - val z = this : B - val Int.xx : Int get() = this : Int - fun Char.xx() : Any { - this : Char - val a = {Double.() -> this : Double + this@xx : Char} - val b = @a{Double.() -> this@a : Double + this@xx : Char} - val c = @a{() -> this@a + this@xx : Char} - return (@a{Double.() -> this@a : Double + this@xx : Char}) - } - } - } diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt new file mode 100644 index 00000000000..4a8aeefdc75 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt @@ -0,0 +1,12 @@ +// FILE: f.kt +class A() { + fun foo() : Unit { + this@A + this@a + this + } + + val x = this@A.foo() + val y = this.foo() + val z = foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Super.kt b/compiler/testData/diagnostics/tests/thisAndSuper/Super.kt similarity index 70% rename from compiler/testData/diagnostics/tests/Super.kt rename to compiler/testData/diagnostics/tests/thisAndSuper/Super.kt index f8048612083..4e5dd94da97 100644 --- a/compiler/testData/diagnostics/tests/Super.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/Super.kt @@ -1,17 +1,5 @@ package example; -fun any(a : Any) {} - -fun notAnExpression() { - any(super) // not an expression - if (super) {} else {} // not an expression - val x = super // not an expression - when (1) { - super -> 1 // not an expression - } - -} - trait T { fun foo() {} } @@ -54,12 +42,6 @@ class A() : C(), T { } } -fun foo() { - super - super.foo() - super.foo() -} - trait G { fun foo() {} } @@ -79,11 +61,4 @@ class ERROR() : UR { fun test() { super.foo() } -} - -// No supertype at all -class A1 { - fun test() { - super.equals(null) - } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.kt b/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.kt new file mode 100644 index 00000000000..a6bf3efd8ce --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.kt @@ -0,0 +1,5 @@ +class Dup { + fun Dup() : Unit { + this@Dup + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt new file mode 100644 index 00000000000..14e3285695c --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt @@ -0,0 +1,6 @@ +// No supertype at all +class A1 { + fun test() { + super.equals(null) // Call to an extension function + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.kt new file mode 100644 index 00000000000..e494e1d88ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.kt @@ -0,0 +1,5 @@ +fun foo() { + super + super.foo() + super.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.kt new file mode 100644 index 00000000000..2699424184f --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.kt @@ -0,0 +1,12 @@ +fun any(a : Any) {} + +fun notAnExpression() { + any(super) // not an expression + if (super) {} else {} // not an expression + val x = super // not an expression + when (1) { + super -> 1 // not an expression + else -> {} + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.kt new file mode 100644 index 00000000000..5cedba746fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.kt @@ -0,0 +1,17 @@ +class A(val a:Int) { + class B() { + fun Char.xx() : Any { + this : Char + val a = { + Double.() -> + this : Double + this@xx : Char + this@B : B + this@A : A + } + val b = @a{Double.() -> this@a : Double + this@xx : Char} + val c = @a{() -> this@a + this@xx : Char} + return (@a{Double.() -> this@a : Double + this@xx : Char}) + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInNestedClasses.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInNestedClasses.kt new file mode 100644 index 00000000000..b88da281e4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInNestedClasses.kt @@ -0,0 +1,9 @@ +class A(val a:Int) { + + class B() { + val x = this@B : B + val y = this@A : A + val z = this : B + val Int.xx : Int get() = this : Int + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.kt new file mode 100644 index 00000000000..f189a07c0ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.kt @@ -0,0 +1,4 @@ +fun foo1() : Unit { + this + this@a +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index ea3fb623914..264c62e5fed 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve; @InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class}) public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve { @TestMetadata("compiler/testData/diagnostics/tests") - @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Tuples.class, Tests.Varargs.class}) + @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.ThisAndSuper.class, Tests.Tuples.class, Tests.Varargs.class}) public static class Tests extends AbstractDiagnosticsTestWithEagerResolve { @TestMetadata("Abstract.kt") public void testAbstract() throws Exception { @@ -391,11 +391,6 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/QualifiedExpressions.kt"); } - @TestMetadata("QualifiedThis.kt") - public void testQualifiedThis() throws Exception { - doTest("compiler/testData/diagnostics/tests/QualifiedThis.kt"); - } - @TestMetadata("RecursiveTypeInference.kt") public void testRecursiveTypeInference() throws Exception { doTest("compiler/testData/diagnostics/tests/RecursiveTypeInference.kt"); @@ -446,11 +441,6 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/StringTemplates.kt"); } - @TestMetadata("Super.kt") - public void testSuper() throws Exception { - doTest("compiler/testData/diagnostics/tests/Super.kt"); - } - @TestMetadata("SupertypeListChecks.kt") public void testSupertypeListChecks() throws Exception { doTest("compiler/testData/diagnostics/tests/SupertypeListChecks.kt"); @@ -3489,6 +3479,59 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage } + @TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper") + public static class ThisAndSuper extends AbstractDiagnosticsTestWithEagerResolve { + public void testAllFilesPresentInThisAndSuper() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/thisAndSuper"), "kt", true); + } + + @TestMetadata("ambigousLabelOnThis.kt") + public void testAmbigousLabelOnThis() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/ambigousLabelOnThis.kt"); + } + + @TestMetadata("QualifiedThis.kt") + public void testQualifiedThis() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt"); + } + + @TestMetadata("Super.kt") + public void testSuper() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/Super.kt"); + } + + @TestMetadata("superInExtensionFunctionCall.kt") + public void testSuperInExtensionFunctionCall() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt"); + } + + @TestMetadata("superInToplevelFunction.kt") + public void testSuperInToplevelFunction() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/superInToplevelFunction.kt"); + } + + @TestMetadata("superIsNotAnExpression.kt") + public void testSuperIsNotAnExpression() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/superIsNotAnExpression.kt"); + } + + @TestMetadata("thisInFunctionLiterals.kt") + public void testThisInFunctionLiterals() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.kt"); + } + + @TestMetadata("thisInNestedClasses.kt") + public void testThisInNestedClasses() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/thisInNestedClasses.kt"); + } + + @TestMetadata("thisInToplevelFunction.kt") + public void testThisInToplevelFunction() throws Exception { + doTest("compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.kt"); + } + + } + @TestMetadata("compiler/testData/diagnostics/tests/tuples") public static class Tuples extends AbstractDiagnosticsTestWithEagerResolve { public void testAllFilesPresentInTuples() throws Exception { @@ -3591,6 +3634,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage suite.addTestSuite(Shadowing.class); suite.addTestSuite(Substitutions.class); suite.addTestSuite(Subtyping.class); + suite.addTestSuite(ThisAndSuper.class); suite.addTestSuite(Tuples.class); suite.addTestSuite(Varargs.class); return suite;