From 761aa9df09311b2fab14ac8ca4c6baf8a52ba337 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 14 Dec 2016 12:30:40 +0100 Subject: [PATCH] Report error when delegation method hides superttype override #KT-12531 Fixed --- .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../kotlin/resolve/TargetPlatform.kt | 3 +- .../resolve/checkers/DelegationChecker.kt | 121 ++++++++++++++++++ .../clashes/finalMemberOverridden.kt | 16 +-- .../covariantOverrides/fromClass.kt | 4 +- .../tests/delegationBy/abstractOverride.kt | 18 +++ .../tests/delegationBy/abstractOverride.txt | 26 ++++ .../tests/delegationBy/delegationToSubType.kt | 19 +++ .../delegationBy/delegationToSubType.txt | 25 ++++ .../delegationToSubTypeProperty.kt | 20 +++ .../delegationToSubTypeProperty.txt | 25 ++++ .../delegationToSubTypeWithOverride.kt | 19 +++ .../delegationToSubTypeWithOverride.txt | 25 ++++ ...delegationToSubTypeWithOverrideProperty.kt | 26 ++++ ...elegationToSubTypeWithOverrideProperty.txt | 25 ++++ .../diagnostics/tests/delegationBy/diamond.kt | 43 +++++++ .../tests/delegationBy/diamond.txt | 56 ++++++++ .../tests/delegationBy/explicitOverride.kt | 18 +++ .../tests/delegationBy/explicitOverride.txt | 26 ++++ .../diagnostics/tests/delegationBy/generic.kt | 14 ++ .../tests/delegationBy/generic.txt | 25 ++++ .../delegationBy/sameDelegationInHierarchy.kt | 16 +++ .../sameDelegationInHierarchy.txt | 26 ++++ .../sameDelegationInHierarchy2.kt | 21 +++ .../sameDelegationInHierarchy2.txt | 33 +++++ .../tests/delegationBy/severalDelegates.kt | 27 ++++ .../tests/delegationBy/severalDelegates.txt | 49 +++++++ .../diagnostics/tests/delegationBy/simple.kt | 19 +++ .../diagnostics/tests/delegationBy/simple.txt | 36 ++++++ .../tests/delegationBy/simpleNoOverride.kt | 15 +++ .../tests/delegationBy/simpleNoOverride.txt | 26 ++++ .../tests/delegationBy/simpleProp.kt | 17 +++ .../tests/delegationBy/simpleProp.txt | 18 +++ .../superTraitAndDelegationToTraitImpl.kt | 2 +- .../override/ObjectDelegationManyImpl.kt | 2 +- .../checkers/DiagnosticsTestGenerated.java | 93 ++++++++++++++ idea/testData/quickfix/abstract/manyImpl.kt | 1 + 38 files changed, 944 insertions(+), 13 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DelegationChecker.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/abstractOverride.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/abstractOverride.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/diamond.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/diamond.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/explicitOverride.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/explicitOverride.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/generic.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/generic.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/severalDelegates.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/severalDelegates.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simple.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simple.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.txt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simpleProp.kt create mode 100644 compiler/testData/diagnostics/tests/delegationBy/simpleProp.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index c58dcf2e3d7..1a40a2536c8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -234,6 +234,7 @@ public interface Errors { DiagnosticFactory0 SUPERTYPE_NOT_INITIALIZED = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 DELEGATION_NOT_TO_INTERFACE = DiagnosticFactory0.create(ERROR); + DiagnosticFactory2> DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE = DiagnosticFactory2.create(ERROR); DiagnosticFactory0 SUPERTYPE_NOT_A_CLASS_OR_INTERFACE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR); 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 4c17fee512c..c4aa6b86074 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -368,6 +368,7 @@ public class DefaultErrorMessages { MAP.put(DELEGATION_IN_INTERFACE, "Interfaces cannot use delegation"); MAP.put(DELEGATION_NOT_TO_INTERFACE, "Only interfaces can be delegated to"); + MAP.put(DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE, "Delegated member ''{0}'' hides supertype override: {1}. Please specify proper override explicitly", COMPACT, commaSeparated(SHORT_NAMES_IN_TYPES)); MAP.put(NO_CONSTRUCTOR, "This class does not have a constructor"); MAP.put(RESOLUTION_TO_CLASSIFIER, "{2}", NAME, TO_STRING, STRING); MAP.put(NOT_A_CLASS, "Not a class"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt index ad1ccb40cbb..51d457a4607 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt @@ -73,7 +73,8 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf( InfixModifierChecker(), SinceKotlinAnnotationValueChecker, ReifiedTypeParameterAnnotationChecker(), - DynamicReceiverChecker + DynamicReceiverChecker, + DelegationChecker() ) private val DEFAULT_CALL_CHECKERS = listOf( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DelegationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DelegationChecker.kt new file mode 100644 index 00000000000..b5f8c5f204c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/DelegationChecker.kt @@ -0,0 +1,121 @@ +/* + * Copyright 2010-2016 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.resolve.checkers + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.diagnostics.DiagnosticSink +import org.jetbrains.kotlin.diagnostics.Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE +import org.jetbrains.kotlin.incremental.components.NoLookupLocation +import org.jetbrains.kotlin.psi.KtClassOrObject +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtDelegatedSuperTypeEntry +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.resolve.MemberComparator +import org.jetbrains.kotlin.resolve.OverridingUtil +import org.jetbrains.kotlin.utils.DFS +import org.jetbrains.kotlin.utils.keysToMapExceptNulls + +class DelegationChecker : SimpleDeclarationChecker { + override fun check( + declaration: KtDeclaration, + descriptor: DeclarationDescriptor, + diagnosticHolder: DiagnosticSink, + bindingContext: BindingContext + ) { + if (descriptor !is ClassDescriptor) return + if (declaration !is KtClassOrObject) return + + val delegationDescriptors = descriptor.defaultType.memberScope.getContributedDescriptors(). + filterIsInstance().filter { it.kind == CallableMemberDescriptor.Kind.DELEGATION }.sortedWith(MemberComparator.INSTANCE) + + for (specifier in declaration.superTypeListEntries) { + if (specifier is KtDelegatedSuperTypeEntry) { + val superType = specifier.typeReference?.let { bindingContext.get(BindingContext.TYPE, it) } ?: continue + val superTypeDescriptor = superType.constructor.declarationDescriptor as? ClassDescriptor ?: continue + + val delegates = getDelegates(delegationDescriptors, superTypeDescriptor) + delegates.forEach { (delegated, delegatedTo) -> + checkDescriptor(declaration, delegated, delegatedTo, diagnosticHolder) + } + } + } + } + + private fun checkDescriptor( + classDeclaration: KtDeclaration, + delegatedDescriptor: CallableMemberDescriptor, + delegatedToDescriptor: CallableMemberDescriptor, + diagnosticHolder: DiagnosticSink + ) { + val reachableFromDelegated = findAllReachableDeclarations(delegatedDescriptor) + reachableFromDelegated.remove(delegatedDescriptor.original) + val toRemove = linkedSetOf() + for (declaration in reachableFromDelegated) { + val reachable = findAllReachableDeclarations(declaration.original) + reachable.remove(declaration) + toRemove.addAll(reachable) + } + reachableFromDelegated.removeAll(toRemove) + reachableFromDelegated.remove(DescriptorUtils.unwrapFakeOverride(delegatedToDescriptor).original) + + val nonAbstractReachable = reachableFromDelegated.filter { it.modality != Modality.ABSTRACT } + + if (nonAbstractReachable.isNotEmpty()) { + /*In case of MANY_IMPL_MEMBER_NOT_IMPLEMENTED error there could be several elements otherwise only one*/ + diagnosticHolder.report(DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE.on(classDeclaration, delegatedDescriptor, nonAbstractReachable.toList())) + } + } + + fun getDelegates( + delegatedMethods: Iterable, + toInterface: ClassDescriptor + ): Map { + return delegatedMethods + .keysToMapExceptNulls { delegatingMember -> + val actualDelegates = DescriptorUtils.getAllOverriddenDescriptors(delegatingMember) + .filter { it.containingDeclaration == toInterface } + .map { overriddenDescriptor -> + val scope = toInterface.defaultType.memberScope + val name = overriddenDescriptor.name + + // this is the actual member of delegateExpressionType that we are delegating to + (scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_OVERRIDES) + + scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_OVERRIDES)) + .firstOrNull { it == overriddenDescriptor || OverridingUtil.overrides(it, overriddenDescriptor) } + } + + actualDelegates.firstOrNull() as? CallableMemberDescriptor + } + } +} + +private fun findAllReachableDeclarations(memberDescriptor: CallableMemberDescriptor): MutableSet { + val collector = object : DFS.NodeHandlerWithListResult() { + override fun afterChildren(current: CallableMemberDescriptor) { + if (current.kind.isReal) { + result.add(current.original) + } + } + } + + DFS.dfs(listOf(memberDescriptor), { it.overriddenDescriptors }, collector) + return java.util.HashSet(collector.result()) +} diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt index 5a99e5f74f4..81eb7d8b85c 100644 --- a/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt +++ b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt @@ -38,18 +38,18 @@ class CBarT : IBarT { override val bar: T get() = null!! } -class Test1 : Final(), IFoo by CFoo() +class Test1 : Final(), IFoo by CFoo() -class Test2 : Final(), IBar by CBar() +class Test2 : Final(), IBar by CBar() -class Test3 : Final(), IQux by CQux() +class Test3 : Final(), IQux by CQux() -class Test4 : Derived(), IFoo by CFoo() +class Test4 : Derived(), IFoo by CFoo() -class Test5 : Derived(), IBar by CBar() +class Test5 : Derived(), IBar by CBar() -class Test6 : Derived(), IQux by CQux() +class Test6 : Derived(), IQux by CQux() -class Test7 : Final(), IBarT by CBarT() +class Test7 : Final(), IBarT by CBarT() -class Test8 : Final(), IBarT by CBar() +class Test8 : Final(), IBarT by CBar() diff --git a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.kt b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.kt index 6ce44d79dd6..ea8d4f5bbaf 100644 --- a/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.kt +++ b/compiler/testData/diagnostics/tests/delegation/covariantOverrides/fromClass.kt @@ -6,7 +6,7 @@ open class IDerived1 : IBase1 { override fun foo(): String = "1" } -class Broken1(val b: IBase1) : IBase1 by b, IDerived1() +class Broken1(val b: IBase1) : IBase1 by b, IDerived1() interface IBase2 { val foo: Any @@ -16,4 +16,4 @@ open class IDerived2 : IBase2 { override val foo: String = "2" } -class Broken2(val b: IBase2) : IBase2 by b, IDerived2() +class Broken2(val b: IBase2) : IBase2 by b, IDerived2() diff --git a/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.kt b/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.kt new file mode 100644 index 00000000000..861ec527e6b --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.kt @@ -0,0 +1,18 @@ +public interface Base { + fun test() = "OK" +} + + +abstract class Impl : Base { + override abstract fun test(): String +} + +class Delegate : Base + + +fun box(): String { + object : Impl(), Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.txt b/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.txt new file mode 100644 index 00000000000..567f6ac590e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/abstractOverride.txt @@ -0,0 +1,26 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base { + public constructor Delegate() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Impl : Base { + public constructor Impl() + 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 abstract override /*1*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.kt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.kt new file mode 100644 index 00000000000..930bd45514c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.kt @@ -0,0 +1,19 @@ +public interface Base { + fun test() = "OK" +} + +public interface Base2 : Base + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + + } + + object : Base2, Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.txt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.txt new file mode 100644 index 00000000000..ce70bcafdc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.txt @@ -0,0 +1,25 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base2 : Base { + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base2 { + public constructor Delegate() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.kt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.kt new file mode 100644 index 00000000000..9c55da1c50c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.kt @@ -0,0 +1,20 @@ +public interface Base { + val test: String + get() = "OK" +} + +public interface Base2 : Base + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + + } + + object : Base2, Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.txt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.txt new file mode 100644 index 00000000000..a2ae2548605 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.txt @@ -0,0 +1,25 @@ +package + +public fun box(): kotlin.String + +public interface Base { + public open val test: 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 +} + +public interface Base2 : Base { + public open override /*1*/ /*fake_override*/ val test: 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 +} + +public final class Delegate : Base2 { + public constructor Delegate() + public open override /*1*/ /*fake_override*/ val test: 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 +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.kt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.kt new file mode 100644 index 00000000000..3a46baf687c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.kt @@ -0,0 +1,19 @@ +public interface Base { + fun test() = "OK" +} + +public interface Base2 : Base { + override fun test() = "OK2" +} + +class Delegate : Base2 + +fun box(): String { + object : Base, Base2 by Delegate() { + } + + object : Base2, Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.txt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.txt new file mode 100644 index 00000000000..9b2c42df4e7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.txt @@ -0,0 +1,25 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base2 : Base { + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base2 { + public constructor Delegate() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.kt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.kt new file mode 100644 index 00000000000..a9a8bea5f54 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.kt @@ -0,0 +1,26 @@ +public interface Base { + var test: String + get() = "OK" + set(s: String) { + } +} + +public interface Base2 : Base { + override var test: String + get() = "OK2" + set(value) {} +} + +class Delegate : Base2 { + +} + +fun box(): String { + object : Base, Base2 by Delegate() { + } + + object : Base2, Base by Delegate() { + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.txt b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.txt new file mode 100644 index 00000000000..6b8abaa44ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.txt @@ -0,0 +1,25 @@ +package + +public fun box(): kotlin.String + +public interface Base { + public open var test: 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 +} + +public interface Base2 : Base { + public open override /*1*/ var test: 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 +} + +public final class Delegate : Base2 { + public constructor Delegate() + public open override /*1*/ /*fake_override*/ var test: 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 +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/diamond.kt b/compiler/testData/diagnostics/tests/delegationBy/diamond.kt new file mode 100644 index 00000000000..5d4dc4857a9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/diamond.kt @@ -0,0 +1,43 @@ +public interface Base { + fun test() = "Base" +} + +public interface Base2 : Base { + override fun test() = "Base2" +} + +public interface Base3 : Base { + override fun test() = "Base3" +} + +class Impl : Base + +class Impl2 : Base2 + +class Impl3 : Base3 + +class ImplAll : Base, Base2, Base3 { + override fun test(): String { + return super.test() + } +} + +fun box(): String { + object : Base2, Base3, Base by Impl() { + + } + + object : Base2 by Impl2(), Base3, Base { + + } + + object : Base2, Base3 by Impl3(), Base { + + } + + object : Base2 by Impl2(), Base3 by Impl3(), Base by Impl() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/diamond.txt b/compiler/testData/diagnostics/tests/delegationBy/diamond.txt new file mode 100644 index 00000000000..939762e1310 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/diamond.txt @@ -0,0 +1,56 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base2 : Base { + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base3 : Base { + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Impl : Base { + public constructor Impl() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Impl2 : Base2 { + public constructor Impl2() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Impl3 : Base3 { + public constructor Impl3() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class ImplAll : Base, Base2, Base3 { + public constructor ImplAll() + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ fun test(): kotlin.String + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.kt b/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.kt new file mode 100644 index 00000000000..d2bc0a749f0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.kt @@ -0,0 +1,18 @@ +public interface Base { + fun test() = "OK" +} + +open class Base2 : Base { + override fun test() = "OK2" +} + +class Delegate : Base + +fun box(): String { + + object : Base2(), Base by Delegate() { + override fun test() = "OK" + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.txt b/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.txt new file mode 100644 index 00000000000..0a6ce9c112b --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/explicitOverride.txt @@ -0,0 +1,26 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Base2 : Base { + public constructor Base2() + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base { + public constructor Delegate() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/generic.kt b/compiler/testData/diagnostics/tests/delegationBy/generic.kt new file mode 100644 index 00000000000..fb4fa1e4ee9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/generic.kt @@ -0,0 +1,14 @@ +public interface Base { + fun test(p: T) = "Base" +} + +public interface Derived : Base + +class Delegate : Derived + +fun box(): String { + object : Derived by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegationBy/generic.txt b/compiler/testData/diagnostics/tests/delegationBy/generic.txt new file mode 100644 index 00000000000..f88fa38f4fd --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/generic.txt @@ -0,0 +1,25 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(/*0*/ p: T): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Derived { + public constructor Delegate() + 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 test(/*0*/ p: Z): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Derived : Base { + 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 test(/*0*/ p: Y): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.kt b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.kt new file mode 100644 index 00000000000..41e3f89b543 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.kt @@ -0,0 +1,16 @@ +public interface Base { + fun test() = "Base" +} + +class Delegate : Base { + override fun test() = "Base" +} + +public open class MyClass : Base by Delegate() + +fun box(): String { + object : MyClass(), Base by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.txt b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.txt new file mode 100644 index 00000000000..749fe00294a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.txt @@ -0,0 +1,26 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base { + public constructor Delegate() + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class MyClass : Base { + public constructor MyClass() + 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*/ /*delegation*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.kt b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.kt new file mode 100644 index 00000000000..72be577b870 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.kt @@ -0,0 +1,21 @@ +public interface Base { + fun test() = "Base" +} + +public interface Derived : Base { + override fun test() = "Derived" +} + + +class Delegate : Derived { + override fun test() = "Delegate" +} + +public open class MyClass : Base by Delegate() + +fun box(): String { + object : MyClass(), Derived by Delegate() { + } + return "OK" +} + diff --git a/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.txt b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.txt new file mode 100644 index 00000000000..2914cdb7c57 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.txt @@ -0,0 +1,33 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Derived { + public constructor Delegate() + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Derived : Base { + 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*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class MyClass : Base { + public constructor MyClass() + 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*/ /*delegation*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.kt b/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.kt new file mode 100644 index 00000000000..2fbe602018d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.kt @@ -0,0 +1,27 @@ +interface Base1 { + fun test() = "OK" +} + +interface Base2 { + fun test2() = "OK" +} + + +class Delegate1 : Base1 + +class Delegate2 : Base2 + + +public abstract class MyClass : Base1, Base2 { + override fun test(): String { + return "Class" + } + + override fun test2(): String { + return "Class" + } +} + +class A : MyClass(), Base1 by Delegate1(), Base1 by Delegate2() { + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.txt b/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.txt new file mode 100644 index 00000000000..539bf26e2f2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/severalDelegates.txt @@ -0,0 +1,49 @@ +package + +public final class A : MyClass, Base1, Base1 { + public constructor A() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*delegation*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun test2(): kotlin.String + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base1 { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base2 { + 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 fun test2(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate1 : Base1 { + public constructor Delegate1() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate2 : Base2 { + public constructor Delegate2() + 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 test2(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class MyClass : Base1, Base2 { + public constructor MyClass() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(): kotlin.String + public open override /*1*/ fun test2(): kotlin.String + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/simple.kt b/compiler/testData/diagnostics/tests/delegationBy/simple.kt new file mode 100644 index 00000000000..ff670ebf053 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simple.kt @@ -0,0 +1,19 @@ +public interface Base { + fun getValue(): String + + fun test() = getValue() +} + +class Delegate : Base { + override fun getValue() = "Delegate" +} + +public abstract class MyClass : Base { + override fun test(): String { + return "Class" + } +} + +class A : MyClass(), Base by Delegate() { + override fun getValue() = "Delegate" +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegationBy/simple.txt b/compiler/testData/diagnostics/tests/delegationBy/simple.txt new file mode 100644 index 00000000000..1355d6b325d --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simple.txt @@ -0,0 +1,36 @@ +package + +public final class A : MyClass, Base { + public constructor A() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ fun getValue(): kotlin.String + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*delegation*/ fun test(): kotlin.String + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Base { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun getValue(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base { + public constructor Delegate() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun getValue(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class MyClass : Base { + public constructor MyClass() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun getValue(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.kt b/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.kt new file mode 100644 index 00000000000..cacaab043f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.kt @@ -0,0 +1,15 @@ +interface Base { + fun test() = "OK" +} + +open class Base2 : Base + +class Delegate : Base + +fun box(): String { + object : Base2(), Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.txt b/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.txt new file mode 100644 index 00000000000..65756be579e --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.txt @@ -0,0 +1,26 @@ +package + +public fun box(): kotlin.String + +public interface Base { + 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 fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Base2 : Base { + public constructor Base2() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Delegate : Base { + public constructor Delegate() + 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 test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/simpleProp.kt b/compiler/testData/diagnostics/tests/delegationBy/simpleProp.kt new file mode 100644 index 00000000000..702521c97d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simpleProp.kt @@ -0,0 +1,17 @@ +public interface Base { + val test: String + get() = "OK" +} + +open class Delegate : Base { + override val test: String + get() = "OK" +} + +fun box(): String { + object : Delegate(), Base by Delegate() { + + } + + return "OK" +} diff --git a/compiler/testData/diagnostics/tests/delegationBy/simpleProp.txt b/compiler/testData/diagnostics/tests/delegationBy/simpleProp.txt new file mode 100644 index 00000000000..b238a87bb1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegationBy/simpleProp.txt @@ -0,0 +1,18 @@ +package + +public fun box(): kotlin.String + +public interface Base { + public open val test: 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 +} + +public open class Delegate : Base { + public constructor Delegate() + public open override /*1*/ val test: 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 +} diff --git a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.kt b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.kt index 32ababfffdd..252f2e813c4 100644 --- a/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.kt +++ b/compiler/testData/diagnostics/tests/duplicateJvmSignature/erasure/superTraitAndDelegationToTraitImpl.kt @@ -10,4 +10,4 @@ interface B { class C(f: A): A by f, B -class D(f: A): A by f, B \ No newline at end of file +class D(f: A): A by f, B \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.kt b/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.kt index 88b245e5a67..523d8d4b97f 100644 --- a/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.kt +++ b/compiler/testData/diagnostics/tests/override/ObjectDelegationManyImpl.kt @@ -10,4 +10,4 @@ object Impl : D, E { override fun foo() {} } -val obj: D = object : D by Impl, E by Impl {} \ No newline at end of file +val obj: D = object : D by Impl, E by Impl {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index ea09d61a166..465761667b6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6209,6 +6209,99 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { } } + @TestMetadata("compiler/testData/diagnostics/tests/delegationBy") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DelegationBy extends AbstractDiagnosticsTest { + @TestMetadata("abstractOverride.kt") + public void testAbstractOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/abstractOverride.kt"); + doTest(fileName); + } + + public void testAllFilesPresentInDelegationBy() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegationBy"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("delegationToSubType.kt") + public void testDelegationToSubType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/delegationToSubType.kt"); + doTest(fileName); + } + + @TestMetadata("delegationToSubTypeProperty.kt") + public void testDelegationToSubTypeProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeProperty.kt"); + doTest(fileName); + } + + @TestMetadata("delegationToSubTypeWithOverride.kt") + public void testDelegationToSubTypeWithOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverride.kt"); + doTest(fileName); + } + + @TestMetadata("delegationToSubTypeWithOverrideProperty.kt") + public void testDelegationToSubTypeWithOverrideProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/delegationToSubTypeWithOverrideProperty.kt"); + doTest(fileName); + } + + @TestMetadata("diamond.kt") + public void testDiamond() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/diamond.kt"); + doTest(fileName); + } + + @TestMetadata("explicitOverride.kt") + public void testExplicitOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/explicitOverride.kt"); + doTest(fileName); + } + + @TestMetadata("generic.kt") + public void testGeneric() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/generic.kt"); + doTest(fileName); + } + + @TestMetadata("sameDelegationInHierarchy.kt") + public void testSameDelegationInHierarchy() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy.kt"); + doTest(fileName); + } + + @TestMetadata("sameDelegationInHierarchy2.kt") + public void testSameDelegationInHierarchy2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/sameDelegationInHierarchy2.kt"); + doTest(fileName); + } + + @TestMetadata("severalDelegates.kt") + public void testSeveralDelegates() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/severalDelegates.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/simple.kt"); + doTest(fileName); + } + + @TestMetadata("simpleNoOverride.kt") + public void testSimpleNoOverride() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/simpleNoOverride.kt"); + doTest(fileName); + } + + @TestMetadata("simpleProp.kt") + public void testSimpleProp() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegationBy/simpleProp.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/tests/deparenthesize") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/testData/quickfix/abstract/manyImpl.kt b/idea/testData/quickfix/abstract/manyImpl.kt index 7ff6935649e..00643c44bbf 100644 --- a/idea/testData/quickfix/abstract/manyImpl.kt +++ b/idea/testData/quickfix/abstract/manyImpl.kt @@ -1,5 +1,6 @@ // "Make 'A' abstract" "false" // ERROR: Class 'X' must override public open fun foo(): Unit defined in X because it inherits many implementations of it +// ERROR: Delegated member 'fun foo(): Unit' hides supertype override: public open fun foo(): Unit defined in E. Please specify proper override explicitly // ACTION: Create test // ACTION: Make internal // ACTION: Make private