From 046189087aa234dc85c7d58abe00df0cd2d7e674 Mon Sep 17 00:00:00 2001 From: dnpetrov Date: Mon, 8 Jun 2015 15:35:32 +0300 Subject: [PATCH] KT-5963 Call to super shouldn't require type specification if there is no conflict Implemented unqualified 'super' type resolution (in BasicExpressionTypingVisitor). No overload resolution of any kind is involved. Corresponding supertype is determined by the expected member name only: - 'super.foo(...)' - function or property (of possibly callable type) 'foo' - 'super.x' - property 'x' Supertype should provide a non-abstract implementation of such member. As a fall-back solution for diagnostics purposes, consider supertypes with abstract implementation of such member. Diagnostics: - AMBIGUOUS_SUPER on 'super', if multiple possible supertypes are available; - ABSTRACT_SUPER_CALL on selector expression, if the only available implementation is abstract. #KT-5963 Fixed --- .../BasicExpressionTypingVisitor.java | 16 +++- .../unqualifiedSuper/unqualifiedSuper.kt | 88 +++++++++++++++++++ .../codegen/box/super/unqualifiedSuper.kt | 66 ++++++++++++++ .../unqualifiedSuperWithDeeperHierarchies.kt | 63 +++++++++++++ .../super/unqualifiedSuperWithLocalClass.kt | 30 +++++++ .../diagnostics/tests/thisAndSuper/Super.kt | 2 +- .../ambiguousSuperWithGenerics.kt | 37 ++++++++ .../ambiguousSuperWithGenerics.txt | 50 +++++++++++ .../unqualifiedSuper/unqualifiedSuper.kt | 57 ++++++++++++ .../unqualifiedSuper/unqualifiedSuper.txt | 38 ++++++++ .../unqualifiedSuperWithAbstractMembers.kt | 39 ++++++++ .../unqualifiedSuperWithAbstractMembers.txt | 34 +++++++ .../unqualifiedSuperWithCallableProperty.kt | 20 +++++ .../unqualifiedSuperWithCallableProperty.txt | 30 +++++++ .../unqualifiedSuperWithDeeperHierarchies.kt | 51 +++++++++++ .../unqualifiedSuperWithDeeperHierarchies.txt | 48 ++++++++++ .../unqualifiedSuperWithGenerics.kt | 22 +++++ .../unqualifiedSuperWithGenerics.txt | 43 +++++++++ .../unqualifiedSuperWithInnerClass.kt | 33 +++++++ .../unqualifiedSuperWithInnerClass.txt | 41 +++++++++ .../unqualifiedSuperWithInterfaces.kt | 28 ++++++ .../unqualifiedSuperWithInterfaces.txt | 27 ++++++ .../unqualifiedSuperWithLocalClass.kt | 21 +++++ .../unqualifiedSuperWithLocalClass.txt | 10 +++ .../unqualifiedSuperWithUnresolvedBase.kt | 53 +++++++++++ .../unqualifiedSuperWithUnresolvedBase.txt | 38 ++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 69 +++++++++++++++ .../BlackBoxCodegenTestGenerated.java | 18 ++++ 28 files changed, 1070 insertions(+), 2 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt create mode 100644 compiler/testData/codegen/box/super/unqualifiedSuper.kt create mode 100644 compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt create mode 100644 compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.txt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt create mode 100644 compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 0bd7542ccd8..e177156ba62 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -67,6 +67,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.checker.JetTypeChecker; import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage; +import org.jetbrains.kotlin.types.expressions.unqualifiedSuper.UnqualifiedSuperPackage; import org.jetbrains.kotlin.util.slicedMap.WritableSlice; import org.jetbrains.kotlin.utils.ThrowingList; @@ -398,7 +399,20 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } else { if (supertypes.size() > 1) { - context.trace.report(AMBIGUOUS_SUPER.on(expression)); + Collection supertypesResolvedFromContext = + UnqualifiedSuperPackage.resolveUnqualifiedSuperFromExpressionContext(expression, supertypes); + if (supertypesResolvedFromContext.size() == 1) { + JetType singleResolvedType = supertypesResolvedFromContext.iterator().next(); + result = substitutor.substitute(singleResolvedType, Variance.INVARIANT); + } + else if (supertypesResolvedFromContext.isEmpty()) { + // No supertype found, either with concrete or abstract members. + // Resolve to 'Any' (this will cause diagnostics for unresolved member reference). + result = components.builtIns.getAnyType(); + } + else { + context.trace.report(AMBIGUOUS_SUPER.on(expression)); + } } else { // supertypes may be empty when all the supertypes are error types (are not resolved, for example) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt new file mode 100644 index 00000000000..8863ff2d1a9 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/unqualifiedSuper/unqualifiedSuper.kt @@ -0,0 +1,88 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.types.expressions.unqualifiedSuper + +import com.intellij.util.SmartList +import org.jetbrains.kotlin.descriptors.MemberDescriptor +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.VariableDescriptor +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.JetCallExpression +import org.jetbrains.kotlin.psi.JetDotQualifiedExpression +import org.jetbrains.kotlin.psi.JetSimpleNameExpression +import org.jetbrains.kotlin.psi.JetSuperExpression +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.utils.addToStdlib.singletonList +import java.util.* + +public fun resolveUnqualifiedSuperFromExpressionContext(superExpression: JetSuperExpression, supertypes: Collection): Collection { + val parentElement = superExpression.getParent() + + if (parentElement is JetDotQualifiedExpression) { + val selectorExpression = parentElement.getSelectorExpression() + when (selectorExpression) { + is JetCallExpression -> { + // super.foo(...): foo can be a function or a property of a callable type + val calleeExpression = selectorExpression.getCalleeExpression() + if (calleeExpression is JetSimpleNameExpression) { + return resolveSupertypesByCalleeName(supertypes, calleeExpression.getReferencedNameAsName()) + } + } + is JetSimpleNameExpression -> { + // super.x: x can be a property only + return resolveSupertypesByPropertyName(supertypes, selectorExpression.getReferencedNameAsName()) + } + } + } + + return emptyList() +} + +private fun resolveSupertypesByCalleeName(supertypes: Collection, calleeName: Name): Collection = + resolveSupertypesByMembers(supertypes) { getFunctionMembers(it, calleeName) + getPropertyMembers(it, calleeName) } + +private fun resolveSupertypesByPropertyName(supertypes: Collection, propertyName: Name): Collection = + resolveSupertypesByMembers(supertypes) { getPropertyMembers(it, propertyName) } + +private inline fun resolveSupertypesByMembers( + supertypes: Collection, + getMembers: (JetType) -> Collection +): Collection { + val withConcreteMembers = SmartList() + val withAnyMembers = SmartList() + + for (supertype in supertypes) { + val members = getMembers(supertype) + if (members.isNotEmpty()) { + withAnyMembers.add(supertype) + if (members any ::isConcreteMember) { + withConcreteMembers.add(supertype) + } + } + } + + return if (withConcreteMembers.isNotEmpty()) withConcreteMembers else withAnyMembers +} + +private fun getFunctionMembers(type: JetType, name: Name): Collection = + type.getMemberScope().getFunctions(name) + +private fun getPropertyMembers(type: JetType, name: Name): Collection = + type.getMemberScope().getProperties(name).filterIsInstanceTo(SmartList()) + +private fun isConcreteMember(memberDescriptor: MemberDescriptor): Boolean = + memberDescriptor.getModality() != Modality.ABSTRACT diff --git a/compiler/testData/codegen/box/super/unqualifiedSuper.kt b/compiler/testData/codegen/box/super/unqualifiedSuper.kt new file mode 100644 index 00000000000..9863671fa68 --- /dev/null +++ b/compiler/testData/codegen/box/super/unqualifiedSuper.kt @@ -0,0 +1,66 @@ +open class Base() { + open fun baseFun(): String = "Base.baseFun()" + + open fun unambiguous(): String = "Base.unambiguous()" + + open val baseProp: String + get() = "Base.baseProp" +} + +interface Interface { + fun interfaceFun(): String = "Interface.interfaceFun()" + + fun unambiguous(): String // NB abstract +} + +interface AnotherInterface + +interface DerivedInterface: Interface, AnotherInterface { + override fun interfaceFun(): String = "DerivedInterface.interfaceFun()" + + override fun unambiguous(): String = "DerivedInterface.unambiguous()" + + fun callsFunFromSuperInterface(): String = super.interfaceFun() +} + +class Derived : Base(), Interface { + override fun baseFun(): String = "Derived.baseFun()" + + override fun unambiguous(): String = "Derived.unambiguous()" + + override fun interfaceFun(): String = "Derived.interfaceFun()" + + override val baseProp: String + get() = "Derived.baseProp" + + fun callsBaseFun(): String = super.baseFun() + + fun callsUnambiguousFun(): String = super.unambiguous() + + fun getsBaseProp(): String = super.baseProp + + fun callsInterfaceFun(): String = super.interfaceFun() +} + +fun box(): String { + val d = Derived() + + val test1 = d.callsBaseFun() + if (test1 != "Base.baseFun()") return "Failed: d.callsBaseFun()==$test1" + + val test2 = d.callsUnambiguousFun() + if (test2 != "Base.unambiguous()") return "Failed: d.callsUnambiguousFun()==$test2" + + val test3 = d.getsBaseProp() + if (test3 != "Base.baseProp") return "Failed: d.getsBaseProp()==$test3" + + val test4 = d.callsInterfaceFun() + if (test4 != "Interface.interfaceFun()") return "Failed: d.callsInterfaceFun()==$test4" + + val di = object : DerivedInterface {} + + val test5 = di.callsFunFromSuperInterface() + if (test5 != "Interface.interfaceFun()") return "Failed: di.callsFunFromSuperInterface()==$test5" + + return "OK" +} diff --git a/compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt b/compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt new file mode 100644 index 00000000000..c9ab55a897d --- /dev/null +++ b/compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt @@ -0,0 +1,63 @@ +open class DeeperBase { + open fun deeperBaseFun(): String = "DeeperBase.deeperBaseFun()" + + open val deeperBaseProp: String + get() = "DeeperBase.deeperBaseProp" +} + +open class DeepBase : DeeperBase() { +} + +interface DeeperInterface { + fun deeperInterfaceFun(): String = "DeeperInterface.deeperInterfaceFun()" + + val deeperInterfaceProp: String + get() = "DeeperInterface.deeperInterfaceProp" +} + +interface DeepInterface : DeeperInterface { + fun deepInterfaceFun(): String = "DeepInterface.deepInterfaceFun()" +} + +class DeepDerived : DeepBase(), DeepInterface { + override fun deeperBaseFun(): String = "DeepDerived.deeperBaseFun()" + + override val deeperBaseProp: String + get() = "DeepDerived.deeperBaseProp" + + override fun deeperInterfaceFun(): String = "DeepDerived.deeperInterfaceFun()" + + override val deeperInterfaceProp: String + get() = "DeepDerived.deeperInterfaceProp" + + override fun deepInterfaceFun(): String = "DeepDerived.deepInterfaceFun()" + + fun callsSuperDeeperBaseFun(): String = super.deeperBaseFun() + + fun getsSuperDeeperBaseProp(): String = super.deeperBaseProp + + fun callsSuperDeepInterfaceFun(): String = super.deepInterfaceFun() + fun callsSuperDeeperInterfaceFun(): String = super.deeperInterfaceFun() + fun getsSuperDeeperInterfaceProp(): String = super.deeperInterfaceProp +} + +fun box(): String { + val dd = DeepDerived() + + val test1 = dd.callsSuperDeeperBaseFun() + if (test1 != "DeeperBase.deeperBaseFun()") return "Failed: dd.callsSuperDeeperBaseFun()==$test1" + + val test2 = dd.getsSuperDeeperBaseProp() + if (test2 != "DeeperBase.deeperBaseProp") return "Failed: dd.getsSuperDeeperBaseProp()==$test2" + + val test3 = dd.callsSuperDeepInterfaceFun() + if (test3 != "DeepInterface.deepInterfaceFun()") return "Failed: dd.callsSuperDeepInterfaceFun()==$test3" + + val test4 = dd.callsSuperDeeperInterfaceFun() + if (test4 != "DeeperInterface.deeperInterfaceFun()") return "Failed: dd.callsSuperDeeperInterfaceFun()==$test4" + + val test5 = dd.getsSuperDeeperInterfaceProp() + if (test5 != "DeeperInterface.deeperInterfaceProp") return "Failed: dd.getsSuperDeeperInterfaceProp()==$test5" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt b/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt new file mode 100644 index 00000000000..a6a592dad00 --- /dev/null +++ b/compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt @@ -0,0 +1,30 @@ +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/diagnostics/tests/thisAndSuper/Super.kt b/compiler/testData/diagnostics/tests/thisAndSuper/Super.kt index db35d1b96c8..f2ccc70c577 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/Super.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/Super.kt @@ -12,7 +12,7 @@ class A() : C(), T { fun test() { super super - super.foo() + super.foo() super.foo() super.bar() super@A.foo() diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt new file mode 100644 index 00000000000..0403356226c --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt @@ -0,0 +1,37 @@ +open class GenericBaseClass { + open fun foo(x: T): T = x + open fun ambiguous(x: T): T = x +} + +interface GenericBaseInterface { + fun bar(x: T): T = x + fun ambiguous(x: T): T = x +} + +class GenericDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: T): T = super.foo(x) + override fun bar(x: T): T = super.bar(x) + + override fun ambiguous(x: T): T = + super.ambiguous(x) +} + +class SpecializedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: String): String = super.bar(x) + + override fun ambiguous(x: String): String = + super.ambiguous(x) + override fun ambiguous(x: Int): Int = + super.ambiguous(x) +} + +class MixedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: T): T = super.bar(x) + + override fun ambiguous(x: Int): Int = + super.ambiguous(x) + override fun ambiguous(x: T): T = + super.ambiguous(x) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.txt new file mode 100644 index 00000000000..0283b9890c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.txt @@ -0,0 +1,50 @@ +package + +internal open class GenericBaseClass { + public constructor GenericBaseClass() + internal open fun ambiguous(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface GenericBaseInterface { + internal open fun ambiguous(/*0*/ x: T): T + internal open fun bar(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class GenericDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor GenericDerivedClass() + internal open override /*2*/ fun ambiguous(/*0*/ x: T): T + internal open override /*1*/ fun bar(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class MixedDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor MixedDerivedClass() + internal open override /*1*/ fun ambiguous(/*0*/ x: T): T + internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.Int): kotlin.Int + internal open override /*1*/ fun bar(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class SpecializedDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor SpecializedDerivedClass() + internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.Int): kotlin.Int + internal open override /*1*/ fun ambiguous(/*0*/ x: kotlin.String): kotlin.String + internal open override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt new file mode 100644 index 00000000000..a64c1d1ac17 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt @@ -0,0 +1,57 @@ +// Base Interface +// \ / +// \/ +// Derived +// + +open class Base() { + open fun foo() {} + + open fun ambiguous() {} + + open val prop: Int + get() = 1234 + + open val ambiguousProp: Int + get() = 111 +} + +interface Interface { + fun bar() {} + + fun ambiguous() {} + + val ambiguousProp: Int + get() = 222 +} + +class Derived : Base(), Interface { + override fun foo() {} + override fun bar() {} + + override fun ambiguous() {} + + override val ambiguousProp: Int + get() = 333 + + override val prop: Int + get() = 4321 + + fun callsFunFromSuperClass() { + super.foo() + } + + fun getSuperProp(): Int = + super.prop + + fun getAmbiguousSuperProp(): Int = + super.ambiguousProp + + fun callsFunFromSuperInterface() { + super.bar() + } + + fun callsAmbiguousSuperFun() { + super.ambiguous() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.txt new file mode 100644 index 00000000000..456411f836a --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.txt @@ -0,0 +1,38 @@ +package + +internal open class Base { + public constructor Base() + internal open val ambiguousProp: kotlin.Int + internal open val prop: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Derived : Base, Interface { + public constructor Derived() + internal open override /*2*/ val ambiguousProp: kotlin.Int + internal open override /*1*/ val prop: kotlin.Int + internal open override /*2*/ fun ambiguous(): kotlin.Unit + internal open override /*1*/ fun bar(): kotlin.Unit + internal final fun callsAmbiguousSuperFun(): kotlin.Unit + internal final fun callsFunFromSuperClass(): kotlin.Unit + internal final fun callsFunFromSuperInterface(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Unit + internal final fun getAmbiguousSuperProp(): kotlin.Int + internal final fun getSuperProp(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface Interface { + internal open val ambiguousProp: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + internal open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt new file mode 100644 index 00000000000..2c948359434 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt @@ -0,0 +1,39 @@ +// fun foo: abstract in A, unresolved in I +// fun bar: implemented in A, abstract in I +// fun qux: abstract in A, abstract in I +// val x: unresolved in A, abstract in I +// val y: abstract in A, implemented in I + +abstract class A { + abstract fun foo(): Int + open fun bar() {} + abstract fun qux() + + abstract val y: Int +} + +interface I { + fun bar() + fun qux() + + val x: Int + val y: Int get() = 111 +} + +class B : A(), I { + override val x: Int = 12345 + override val y: Int = super.y + + override fun foo(): Int { + super.foo() + return super.x + } + + override fun bar() { + super.bar() + } + + override fun qux() { + super.qux() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.txt new file mode 100644 index 00000000000..cdbc8c085cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.txt @@ -0,0 +1,34 @@ +package + +internal abstract class A { + public constructor A() + internal abstract val y: kotlin.Int + internal open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal abstract fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal abstract fun qux(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class B : A, I { + public constructor B() + internal open override /*1*/ val x: kotlin.Int = 12345 + internal open override /*2*/ val y: kotlin.Int + internal open override /*2*/ fun bar(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal open override /*2*/ fun qux(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface I { + internal abstract val x: kotlin.Int + internal open val y: kotlin.Int + internal abstract fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal abstract fun qux(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt new file mode 100644 index 00000000000..395986d1a41 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt @@ -0,0 +1,20 @@ +// Ambiguity between fun and callable property + +open class BaseWithCallableProp { + val fn = { "fn.invoke()" } + + val bar = { "bar.invoke()"} + open fun bar(): String = "bar()" +} + +interface InterfaceWithFun { + fun fn(): String = "fn()" +} + +class DerivedUsingFun : BaseWithCallableProp(), InterfaceWithFun { + fun foo(): String = + super.fn() + + override fun bar(): String = + super.bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.txt new file mode 100644 index 00000000000..bc87023de54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.txt @@ -0,0 +1,30 @@ +package + +internal open class BaseWithCallableProp { + public constructor BaseWithCallableProp() + internal final val bar: () -> kotlin.String + internal final val fn: () -> kotlin.String + internal open fun bar(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class DerivedUsingFun : BaseWithCallableProp, InterfaceWithFun { + public constructor DerivedUsingFun() + internal final override /*1*/ /*fake_override*/ val bar: () -> kotlin.String + internal final override /*1*/ /*fake_override*/ val fn: () -> kotlin.String + internal open override /*1*/ fun bar(): kotlin.String + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ /*fake_override*/ fun fn(): kotlin.String + internal final fun foo(): kotlin.String + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface InterfaceWithFun { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun fn(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt new file mode 100644 index 00000000000..a0eebd4d95f --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt @@ -0,0 +1,51 @@ +// Check that it works with inherited members +// +// DeeperBase DeeperInterface +// | | +// DeepBase DeepInterface +// \ / +// \/ +// DeepDerived +// + +open class DeeperBase { + open fun deeperBaseFun() {} + + open val deeperBaseProp: Int + get() = 333 +} + +open class DeepBase : DeeperBase() { +} + +interface DeeperInterface { + fun deeperInterfaceFun() {} +} + +interface DeepInterface : DeeperInterface { + fun deepInterfaceFun() {} +} + +class DeepDerived : DeepBase(), DeepInterface { + override fun deeperBaseFun() {} + + override val deeperBaseProp: Int + get() = 444 + + override fun deeperInterfaceFun() {} + override fun deepInterfaceFun() {} + + fun callsSuperDeeperBaseFun() { + super.deeperBaseFun() + } + + fun getsSuperDeeperBaseProp(): Int = + super.deeperBaseProp + + fun callsSuperInterfaceFuns() { + super.deeperInterfaceFun() + super.deepInterfaceFun() + super.deeperInterfaceFun() + super.deepInterfaceFun() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.txt new file mode 100644 index 00000000000..43edd81c52b --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.txt @@ -0,0 +1,48 @@ +package + +internal open class DeepBase : DeeperBase { + public constructor DeepBase() + internal open override /*1*/ /*fake_override*/ val deeperBaseProp: kotlin.Int + internal open override /*1*/ /*fake_override*/ fun deeperBaseFun(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class DeepDerived : DeepBase, DeepInterface { + public constructor DeepDerived() + internal open override /*1*/ val deeperBaseProp: kotlin.Int + internal final fun callsSuperDeeperBaseFun(): kotlin.Unit + internal final fun callsSuperInterfaceFuns(): kotlin.Unit + internal open override /*1*/ fun deepInterfaceFun(): kotlin.Unit + internal open override /*1*/ fun deeperBaseFun(): kotlin.Unit + internal open override /*1*/ fun deeperInterfaceFun(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal final fun getsSuperDeeperBaseProp(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface DeepInterface : DeeperInterface { + internal open fun deepInterfaceFun(): kotlin.Unit + internal open override /*1*/ /*fake_override*/ fun deeperInterfaceFun(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal open class DeeperBase { + public constructor DeeperBase() + internal open val deeperBaseProp: kotlin.Int + internal open fun deeperBaseFun(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface DeeperInterface { + internal open fun deeperInterfaceFun(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt new file mode 100644 index 00000000000..5291a7dad0e --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt @@ -0,0 +1,22 @@ +open class GenericBaseClass { + open fun foo(x: T): T = x +} + +interface GenericBaseInterface { + fun bar(x: T): T = x +} + +class GenericDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: T): T = super.foo(x) + override fun bar(x: T): T = super.bar(x) +} + +class SpecializedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: String): String = super.bar(x) +} + +class MixedDerivedClass : GenericBaseClass(), GenericBaseInterface { + override fun foo(x: Int): Int = super.foo(x) + override fun bar(x: T): T = super.bar(x) +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.txt new file mode 100644 index 00000000000..e3a4640dd25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.txt @@ -0,0 +1,43 @@ +package + +internal open class GenericBaseClass { + public constructor GenericBaseClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface GenericBaseInterface { + internal open fun bar(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class GenericDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor GenericDerivedClass() + internal open override /*1*/ fun bar(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class MixedDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor MixedDerivedClass() + internal open override /*1*/ fun bar(/*0*/ x: T): T + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class SpecializedDerivedClass : GenericBaseClass, GenericBaseInterface { + public constructor SpecializedDerivedClass() + internal open override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(/*0*/ x: kotlin.Int): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt new file mode 100644 index 00000000000..a7e2bb47dcb --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt @@ -0,0 +1,33 @@ +open class A { + open fun foo() {} +} + +interface B { + fun bar() {} +} + +interface Q { + fun qux() {} +} + +class C : A(), B { + override fun foo() { + super@C.foo() + } + + override fun bar() { + super@C.bar() + } + + inner class D : A(), Q { + override fun foo() { + super@C.foo() + super@D.foo() + } + + override fun qux() { + super@C.qux() + super@D.qux() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.txt new file mode 100644 index 00000000000..d32032bbf6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.txt @@ -0,0 +1,41 @@ +package + +internal open class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface B { + internal open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class C : A, B { + public constructor C() + internal open override /*1*/ fun bar(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String + + internal final inner class D : A, Q { + public constructor D() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal open override /*1*/ fun qux(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +internal interface Q { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal open fun qux(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt new file mode 100644 index 00000000000..e47de8d4306 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt @@ -0,0 +1,28 @@ +// Interface AnotherInterface +// \ / +// \/ +// DerivedInterface +// + +interface Interface { + fun foo() {} + fun ambiguous() {} + val ambiguousProp: Int + get() = 222 +} + +interface AnotherInterface { + fun ambiguous() {} + val ambiguousProp: Int + get() = 333 +} + +interface DerivedInterface: Interface, AnotherInterface { + override fun foo() { super.foo() } + override fun ambiguous() { + super.ambiguous() + } + override val ambiguousProp: Int + get() = super.ambiguousProp +} + diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.txt new file mode 100644 index 00000000000..768e3e3e0be --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.txt @@ -0,0 +1,27 @@ +package + +internal interface AnotherInterface { + internal open val ambiguousProp: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface DerivedInterface : Interface, AnotherInterface { + internal open override /*2*/ val ambiguousProp: kotlin.Int + internal open override /*2*/ fun ambiguous(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface Interface { + internal open val ambiguousProp: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt new file mode 100644 index 00000000000..51bb88b6904 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt @@ -0,0 +1,21 @@ +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 + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.txt new file mode 100644 index 00000000000..0eac66f6535 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.txt @@ -0,0 +1,10 @@ +package + +internal fun withLocalClasses(/*0*/ param: kotlin.Int): Interface + +internal interface Interface { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal abstract fun foo(/*0*/ x: kotlin.Int): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt new file mode 100644 index 00000000000..62be85258c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt @@ -0,0 +1,53 @@ +// Check that unresolved super type doesn't interfere with unqualified super resolution. + +open class Base() { + open fun foo() {} + + open fun ambiguous() {} + + open val prop: Int + get() = 1234 + + open val ambiguousProp: Int + get() = 111 +} + +interface Interface { + fun bar() {} + + fun ambiguous() {} + + val ambiguousProp: Int + get() = 222 +} + +class ClassDerivedFromUnresolved : Base(), Interface, Unresolved { + override fun foo() {} + override fun bar() {} + + override fun ambiguous() {} + + override val ambiguousProp: Int + get() = 333 + + override val prop: Int + get() = 4321 + + fun callsFunFromSuperClass() { + super.foo() + } + + fun getSuperProp(): Int = + super.prop + + fun getAmbiguousSuperProp(): Int = + super.ambiguousProp + + fun callsFunFromSuperInterface() { + super.bar() + } + + fun callsAmbiguousSuperFun() { + super.ambiguous() + } +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.txt b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.txt new file mode 100644 index 00000000000..15722cca3d1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.txt @@ -0,0 +1,38 @@ +package + +internal open class Base { + public constructor Base() + internal open val ambiguousProp: kotlin.Int + internal open val prop: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class ClassDerivedFromUnresolved : Base, Interface { + public constructor ClassDerivedFromUnresolved() + internal open override /*2*/ val ambiguousProp: kotlin.Int + internal open override /*1*/ val prop: kotlin.Int + internal open override /*2*/ fun ambiguous(): kotlin.Unit + internal open override /*1*/ fun bar(): kotlin.Unit + internal final fun callsAmbiguousSuperFun(): kotlin.Unit + internal final fun callsFunFromSuperClass(): kotlin.Unit + internal final fun callsFunFromSuperInterface(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal open override /*1*/ fun foo(): kotlin.Unit + internal final fun getAmbiguousSuperProp(): kotlin.Int + internal final fun getSuperProp(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal interface Interface { + internal open val ambiguousProp: kotlin.Int + internal open fun ambiguous(): kotlin.Unit + internal open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index f88255e2293..50506a2e677 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -13406,6 +13406,75 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/traitSuperCall.kt"); doTest(fileName); } + + @TestMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class UnqualifiedSuper extends AbstractJetDiagnosticsTest { + public void testAllFilesPresentInUnqualifiedSuper() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("ambiguousSuperWithGenerics.kt") + public void testAmbiguousSuperWithGenerics() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/ambiguousSuperWithGenerics.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuper.kt") + public void testUnqualifiedSuper() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuper.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithAbstractMembers.kt") + public void testUnqualifiedSuperWithAbstractMembers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithAbstractMembers.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithCallableProperty.kt") + public void testUnqualifiedSuperWithCallableProperty() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithCallableProperty.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithDeeperHierarchies.kt") + public void testUnqualifiedSuperWithDeeperHierarchies() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithDeeperHierarchies.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithGenerics.kt") + public void testUnqualifiedSuperWithGenerics() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithGenerics.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithInnerClass.kt") + public void testUnqualifiedSuperWithInnerClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInnerClass.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithInterfaces.kt") + public void testUnqualifiedSuperWithInterfaces() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithInterfaces.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithLocalClass.kt") + public void testUnqualifiedSuperWithLocalClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithLocalClass.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithUnresolvedBase.kt") + public void testUnqualifiedSuperWithUnresolvedBase() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/unqualifiedSuper/unqualifiedSuperWithUnresolvedBase.kt"); + doTest(fileName); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/traitWithRequired") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 2563cbf4ed9..72b0d92d41a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -6807,6 +6807,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/traitproperty.kt"); doTest(fileName); } + + @TestMetadata("unqualifiedSuper.kt") + public void testUnqualifiedSuper() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuper.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithDeeperHierarchies.kt") + public void testUnqualifiedSuperWithDeeperHierarchies() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithDeeperHierarchies.kt"); + doTest(fileName); + } + + @TestMetadata("unqualifiedSuperWithLocalClass.kt") + public void testUnqualifiedSuperWithLocalClass() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/super/unqualifiedSuperWithLocalClass.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/superConstructorCall")