From 2fee9d362ceae7a0b42d887c18cf687c7c76f460 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 8 Oct 2015 20:06:26 +0300 Subject: [PATCH] Local interfaces are forbidden now --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/resolve/DeclarationsChecker.java | 3 ++ .../dontGenerateBodyInTrait.kt | 10 ----- .../super/unqualifiedSuperWithLocalClass.kt | 30 ------------- .../deepLocalHierarchy.kt | 6 +-- .../testData/codegen/box/traits/kt5495.kt | 9 ---- .../diagnostics/tests/localInterfaces.kt | 14 +++++++ .../diagnostics/tests/localInterfaces.txt | 3 ++ .../unqualifiedSuperWithLocalClass.kt | 2 +- .../unsupportedFeatures/localClassifier.kt | 2 +- .../checkers/JetDiagnosticsTestGenerated.java | 6 +++ .../KotlinSyntheticClassAnnotationTest.java | 14 ------- .../BlackBoxCodegenTestGenerated.java | 18 -------- .../internalClasses/InternalClasses.kt | 3 -- .../classesAndObjects/commonSuperclasses.kt | 24 ----------- .../commonSuperclasses.kt.match | 3 -- .../classesAndObjects/matchedSuperclasses.kt | 42 ------------------- .../matchedSuperclasses.kt.match | 17 -------- .../classesAndObjects/superTypeOrder.kt | 25 ----------- .../classesAndObjects/superTypeOrder.kt.match | 3 -- .../typeParameters/boundsAndConstraints.kt | 2 +- .../JetPsiUnifierTestGenerated.java | 18 -------- .../lookupTracker/localDeclarations/locals.kt | 8 ++-- 24 files changed, 38 insertions(+), 226 deletions(-) delete mode 100644 compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt delete mode 100644 compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt delete mode 100644 compiler/testData/codegen/box/traits/kt5495.kt create mode 100644 compiler/testData/diagnostics/tests/localInterfaces.kt create mode 100644 compiler/testData/diagnostics/tests/localInterfaces.txt delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt.match delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt.match delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt delete mode 100644 idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt.match diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 0ba5aa13957..9c140537876 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -246,6 +246,7 @@ public interface Errors { // Objects DiagnosticFactory1 LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); + DiagnosticFactory1 LOCAL_INTERFACE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME); // Type parameter declarations diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 994d932e34c..677254ab404 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -292,6 +292,7 @@ public class DefaultErrorMessages { MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING); MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME); + MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME); MAP.put(ENUM_CLASS_CONSTRUCTOR_CALL, "Enum types cannot be instantiated"); MAP.put(SEALED_CLASS_CONSTRUCTOR_CALL, "Sealed types cannot be instantiated"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index 7860a5cd4c6..8de99a50183 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -287,6 +287,9 @@ public class DeclarationsChecker { if (aClass.isInterface()) { checkConstructorInTrait(aClass); + if (aClass.isLocal() && !(classDescriptor.getContainingDeclaration() instanceof ClassDescriptor)) { + trace.report(LOCAL_INTERFACE_NOT_ALLOWED.on(aClass, classDescriptor)); + } } else if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) { checkAnnotationClassWithBody(aClass); diff --git a/compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt b/compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt deleted file mode 100644 index 65cfb766528..00000000000 --- a/compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt +++ /dev/null @@ -1,10 +0,0 @@ -interface A : Collection -interface B : List -interface C : Map -interface D : Map.Entry -interface E : Iterator - -fun box(): String { - interface F : A, B, C, D, E - return "OK" -} diff --git a/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt b/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt deleted file mode 100644 index a6a592dad00..00000000000 --- a/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt +++ /dev/null @@ -1,30 +0,0 @@ -interface Interface { - fun foo(x: Int): Int -} - -fun withLocalClasses(param: Int): Interface { - open class LocalBase { - open val param: Int - get() = 100 - } - - interface LocalInterface : Interface { - override fun foo(x: Int): Int = - x + param - } - - return object : LocalBase(), LocalInterface { - override fun foo(x: Int): Int = - x + super.param - } - -} - -fun box(): String { - val t = withLocalClasses(1) - - val test1 = t.foo(10) - if (test1 != 110) return "Fail: t.foo(10)==$test1" - - return "OK" -} \ No newline at end of file diff --git a/compiler/testData/codegen/box/superConstructorCall/deepLocalHierarchy.kt b/compiler/testData/codegen/box/superConstructorCall/deepLocalHierarchy.kt index 1b596e12610..760f7b0deae 100644 --- a/compiler/testData/codegen/box/superConstructorCall/deepLocalHierarchy.kt +++ b/compiler/testData/codegen/box/superConstructorCall/deepLocalHierarchy.kt @@ -1,9 +1,9 @@ fun box(): String { - interface L1 { - fun foo(): String + abstract class L1 { + abstract fun foo(): String } - open class L2(val s: String) : L1 { + open class L2(val s: String) : L1() { override fun foo() = s } diff --git a/compiler/testData/codegen/box/traits/kt5495.kt b/compiler/testData/codegen/box/traits/kt5495.kt deleted file mode 100644 index 5d541929589..00000000000 --- a/compiler/testData/codegen/box/traits/kt5495.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun box(): String { - interface A { - fun foo() = "OK" - } - - class B : A - - return B().foo() -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/localInterfaces.kt b/compiler/testData/diagnostics/tests/localInterfaces.kt new file mode 100644 index 00000000000..f87ae26abbe --- /dev/null +++ b/compiler/testData/diagnostics/tests/localInterfaces.kt @@ -0,0 +1,14 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun foo() { + interface a {} + val b = object { + interface c {} + } + class A { + interface d {} + } + val f = { + interface e {} + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/localInterfaces.txt b/compiler/testData/diagnostics/tests/localInterfaces.txt new file mode 100644 index 00000000000..65a6ac47e1f --- /dev/null +++ b/compiler/testData/diagnostics/tests/localInterfaces.txt @@ -0,0 +1,3 @@ +package + +public fun foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt index 51bb88b6904..1fa5cf4008c 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt @@ -8,7 +8,7 @@ fun withLocalClasses(param: Int): Interface { get() = 100 } - interface LocalInterface : Interface { + interface LocalInterface : Interface { override fun foo(x: Int): Int = x + param } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/localClassifier.kt b/compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/localClassifier.kt index caafd08d4de..e917ddc5155 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/localClassifier.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/unsupportedFeatures/localClassifier.kt @@ -7,6 +7,6 @@ fun foo() { } } - interface T { + interface T { } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index b0e04f61566..616061e5b95 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -325,6 +325,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("localInterfaces.kt") + public void testLocalInterfaces() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/localInterfaces.kt"); + doTest(fileName); + } + @TestMetadata("MultilineStringTemplates.kt") public void testMultilineStringTemplates() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/MultilineStringTemplates.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java index 9ec16af4125..1dbebfeabb8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java @@ -92,20 +92,6 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { ); } - public void testLocalTraitImpl() { - doTestKotlinSyntheticClass( - "fun foo() { interface Local { fun bar() = 42 } }", - "Local$DefaultImpls.class" - ); - } - - public void testLocalTraitInterface() { - doTestKotlinClass( - "fun foo() { interface Local { fun bar() = 42 } }", - "Local.class" - ); - } - public void testInnerClassOfLocalClass() { doTestKotlinClass( "fun foo() { class Local { inner class Inner } }", diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 6c41e3dddce..f65b017b765 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -778,12 +778,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("dontGenerateBodyInTrait.kt") - public void testDontGenerateBodyInTrait() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/dontGenerateBodyInTrait.kt"); - doTest(fileName); - } - @TestMetadata("implementationInTrait.kt") public void testImplementationInTrait() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/builtinStubMethods/implementationInTrait.kt"); @@ -7432,12 +7426,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("unqualifiedSuperWithLocalClass.kt") - public void testUnqualifiedSuperWithLocalClass() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt"); - doTest(fileName); - } - @TestMetadata("unqualifiedSuperWithMethodsOfAny.kt") public void testUnqualifiedSuperWithMethodsOfAny() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithMethodsOfAny.kt"); @@ -7681,12 +7669,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("kt5495.kt") - public void testKt5495() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/kt5495.kt"); - doTest(fileName); - } - @TestMetadata("multiple.kt") public void testMultiple() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/traits/multiple.kt"); diff --git a/idea/testData/decompiler/internalClasses/InternalClasses.kt b/idea/testData/decompiler/internalClasses/InternalClasses.kt index aeae7c383ae..0a746494da8 100644 --- a/idea/testData/decompiler/internalClasses/InternalClasses.kt +++ b/idea/testData/decompiler/internalClasses/InternalClasses.kt @@ -23,9 +23,6 @@ fun f() { class MyLocalClass { } - interface MyLocalTrait { - } - val myAnonymousObject = object { } diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt b/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt deleted file mode 100644 index f3e3b37f671..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt +++ /dev/null @@ -1,24 +0,0 @@ -fun foo() { - open class Z(p: Int) - interface T; - - { - class A: Z(1), T - } - - { - class B: Z(1), T - } - - { - class C: Z(1) - } - - { - class D: Z(2), T - } - - { - class E: T - } -} \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt.match b/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt.match deleted file mode 100644 index ecfd99eda3e..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt.match +++ /dev/null @@ -1,3 +0,0 @@ -class A: Z(1), T - -class B: Z(1), T \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt b/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt deleted file mode 100644 index 8843d86b9d6..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt +++ /dev/null @@ -1,42 +0,0 @@ -fun foo() { - { - open class Z(p: T) - interface T - class A: Z(1), T - } - - { - open class Z(r: A) - interface T - class B: Z(1), T - } - - { - open class T(r: A) - interface Z - class C: T(1), Z - } - - { - open class Z(q: T) - interface T - class D: Z(2), T - } - - { - open class Z(q: T) - class E: Z(1) - } - - { - open class Z(r: A) - interface T - class F: Z("1"), T - } - - { - open class Z(r: Int) - interface T - class B: Z(1), T - } -} \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt.match b/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt.match deleted file mode 100644 index 62933251f1b..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt.match +++ /dev/null @@ -1,17 +0,0 @@ -{ - open class Z(p: T) - interface T - class A: Z(1), T - } - -{ - open class Z(r: A) - interface T - class B: Z(1), T - } - -{ - open class T(r: A) - interface Z - class C: T(1), Z - } \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt b/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt deleted file mode 100644 index 5ba8733e1b7..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt +++ /dev/null @@ -1,25 +0,0 @@ -fun foo() { - open class Z(p: Int) - interface T - interface U; - - { - class A: Z(1), T, U - } - - { - class B: Z(1), U, T - } - - { - class C: Z(1) - } - - { - class D: Z(1), T - } - - { - class E: Z(1), U - } -} \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt.match b/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt.match deleted file mode 100644 index db0c8f0b18a..00000000000 --- a/idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt.match +++ /dev/null @@ -1,3 +0,0 @@ -class A: Z(1), T, U - -class B: Z(1), U, T \ No newline at end of file diff --git a/idea/testData/unifier/equivalence/declarations/typeParameters/boundsAndConstraints.kt b/idea/testData/unifier/equivalence/declarations/typeParameters/boundsAndConstraints.kt index 738fcc08a50..f48e39c1c6a 100644 --- a/idea/testData/unifier/equivalence/declarations/typeParameters/boundsAndConstraints.kt +++ b/idea/testData/unifier/equivalence/declarations/typeParameters/boundsAndConstraints.kt @@ -1,5 +1,5 @@ fun foo() { - interface T + abstract class T fun bar1(a: A, b: B, c: C): A where B: A, C: B, C: T = c diff --git a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java index 64ac7eb507c..4e0635b7351 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/JetPsiUnifierTestGenerated.java @@ -179,12 +179,6 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest { doTest(fileName); } - @TestMetadata("commonSuperclasses.kt") - public void testCommonSuperclasses() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/commonSuperclasses.kt"); - doTest(fileName); - } - @TestMetadata("delegation.kt") public void testDelegation() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/delegation.kt"); @@ -209,23 +203,11 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest { doTest(fileName); } - @TestMetadata("matchedSuperclasses.kt") - public void testMatchedSuperclasses() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/matchedSuperclasses.kt"); - doTest(fileName); - } - @TestMetadata("members.kt") public void testMembers() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/members.kt"); doTest(fileName); } - - @TestMetadata("superTypeOrder.kt") - public void testSuperTypeOrder() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/declarations/classesAndObjects/superTypeOrder.kt"); - doTest(fileName); - } } @TestMetadata("idea/testData/unifier/equivalence/declarations/localCallables") diff --git a/jps-plugin/testData/incremental/lookupTracker/localDeclarations/locals.kt b/jps-plugin/testData/incremental/lookupTracker/localDeclarations/locals.kt index 534ee1d4fc3..4de42a1547a 100644 --- a/jps-plugin/testData/incremental/lookupTracker/localDeclarations/locals.kt +++ b/jps-plugin/testData/incremental/lookupTracker/localDeclarations/locals.kt @@ -10,12 +10,12 @@ import bar.* fun localFun() = b fun /*p:local.declarations*/Int.localExtFun() = localFun() - interface LocalI { - var a: /*p:local.declarations*/Int - fun foo() + abstract class LocalI { + abstract var a: /*p:local.declarations*/Int + abstract fun foo() } - class LocalC : LocalI { + class LocalC : LocalI() { override var a = 1 override fun foo() {}