diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 96f39e7b050..f8746588123 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -331,10 +331,6 @@ public interface Errors { DiagnosticFactory2 OVERRIDING_FINAL_MEMBER_BY_DELEGATION = DiagnosticFactory2.create(ERROR, DECLARATION_NAME); - DiagnosticFactory2 RETURN_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION = - DiagnosticFactory2.create(ERROR, DECLARATION_NAME); - DiagnosticFactory2 PROPERTY_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION = - DiagnosticFactory2.create(ERROR, DECLARATION_NAME); DiagnosticFactory2 VAR_OVERRIDDEN_BY_VAL_BY_DELEGATION = DiagnosticFactory2.create(ERROR, DECLARATION_NAME); 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 c1736a1a028..7e52fea50fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -565,10 +565,6 @@ public class DefaultErrorMessages { MAP.put(OVERRIDING_FINAL_MEMBER_BY_DELEGATION, "''{0}'' implicitly overrides a final member ''{1}'' by delegation", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); - MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION, "Return type of ''{0}'' doesn't match ''{1}'' implicitly overridden by delegation", - SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); - MAP.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION, "Property type of ''{0}'' doesn't match ''{1}'' implicitly overridden by delegation", - SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); MAP.put(VAR_OVERRIDDEN_BY_VAL_BY_DELEGATION, "val-property ''{0}'' implicitly overrides a var-property ''{1}'' by delegation", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java index 0a8c6ff4fb3..df2242e110c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.java @@ -290,7 +290,7 @@ public class OverrideResolver { } private static class CollectMissingImplementationsStrategy implements CheckInheritedSignaturesReportStrategy { - private Set shouldImplement = new LinkedHashSet(); + private final Set shouldImplement = new LinkedHashSet(); @Override public void abstractMemberNotImplemented(CallableMemberDescriptor descriptor) { @@ -401,8 +401,7 @@ public class OverrideResolver { @NotNull CallableMemberDescriptor overriding, @NotNull CallableMemberDescriptor overridden ) { - conflictingReturnTypes.add(overridden); - reportDelegationProblemIfRequired(RETURN_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION, overriding, overridden); + // Always reported as RETURN_TYPE_MISMATCH_ON_INHERITANCE } @Override @@ -410,8 +409,7 @@ public class OverrideResolver { @NotNull CallableMemberDescriptor overriding, @NotNull CallableMemberDescriptor overridden ) { - conflictingReturnTypes.add(overridden); - reportDelegationProblemIfRequired(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE_BY_DELEGATION, overriding, overridden); + // Always reported as PROPERTY_TYPE_MISMATCH_ON_INHERITANCE } @Override @@ -487,9 +485,7 @@ public class OverrideResolver { if (descriptor.getVisibility() == Visibilities.INVISIBLE_FAKE) return; Collection directOverridden = descriptor.getOverriddenDescriptors(); - if (directOverridden.size() == 0) { - throw new IllegalStateException(kind + " " + descriptor.getName().asString() + " must override something"); - } + assert !directOverridden.isEmpty() : kind + " " + descriptor.getName().asString() + " must override something"; // collects map from the directly overridden descriptor to the set of declarations: // -- if directly overridden is not fake, the set consists of one element: this directly overridden @@ -505,14 +501,12 @@ public class OverrideResolver { checkInheritedDescriptorsGroup(relevantDirectlyOverridden, reportingStrategy); - if (kind == DELEGATION) { - if (overrideReportStrategyForDelegates != null) { - checkOverridesForMember(descriptor, relevantDirectlyOverridden, overrideReportStrategyForDelegates); - } + if (kind == DELEGATION && overrideReportStrategyForDelegates != null) { + checkOverridesForMember(descriptor, relevantDirectlyOverridden, overrideReportStrategyForDelegates); } if (kind != DELEGATION) { - checkMissingOverridesByJava8Restrictions(descriptor, relevantDirectlyOverridden, reportingStrategy); + checkMissingOverridesByJava8Restrictions(relevantDirectlyOverridden, reportingStrategy); } List implementations = collectImplementations(relevantDirectlyOverridden); @@ -549,7 +543,6 @@ public class OverrideResolver { } private static void checkMissingOverridesByJava8Restrictions( - @NotNull CallableMemberDescriptor descriptor, @NotNull Set relevantDirectlyOverridden, @NotNull CheckInheritedSignaturesReportStrategy reportingStrategy ) { @@ -874,8 +867,8 @@ public class OverrideResolver { } private static void checkOverridesForMember( - CallableMemberDescriptor memberDescriptor, - Collection overriddenDescriptors, + @NotNull CallableMemberDescriptor memberDescriptor, + @NotNull Collection overriddenDescriptors, @NotNull CheckOverrideReportStrategy reportError ) { for (CallableMemberDescriptor overridden : overriddenDescriptors) { diff --git a/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt index ccdb6191d74..906b40675ab 100644 --- a/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt +++ b/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt @@ -10,9 +10,9 @@ interface Three { public fun foo(): String } -class Test123(val v1: One, val v2: Two, val v3: Three) : One by v1, Two by v2, Three by v3 { } -class Test132(val v1: One, val v2: Two, val v3: Three) : One by v1, Three by v3, Two by v2 { } +class Test123(val v1: One, val v2: Two, val v3: Three) : One by v1, Two by v2, Three by v3 { } +class Test132(val v1: One, val v2: Two, val v3: Three) : One by v1, Three by v3, Two by v2 { } class Test312(val v1: One, val v2: Two, val v3: Three) : Three by v3, One by v1, Two by v2 { } class Test321(val v1: One, val v2: Two, val v3: Three) : Three by v3, Two by v2, One by v1 { } -class Test231(val v1: One, val v2: Two, val v3: Three) : Two by v2, Three by v3, One by v1 { } -class Test213(val v1: One, val v2: Two, val v3: Three) : Two by v2, One by v1, Three by v3 { } \ No newline at end of file +class Test231(val v1: One, val v2: Two, val v3: Three) : Two by v2, Three by v3, One by v1 { } +class Test213(val v1: One, val v2: Two, val v3: Three) : Two by v2, One by v1, Three by v3 { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt new file mode 100644 index 00000000000..5a99e5f74f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt @@ -0,0 +1,55 @@ +open class Final { + fun foo() {} + val bar: Int = 0 + var qux: Int = 0 +} + +open class Derived : Final() + +interface IFoo { + fun foo() +} + +class CFoo : IFoo { + override fun foo() {} +} + +interface IBar { + val bar: Int +} + +class CBar : IBar { + override val bar: Int get() = 0 +} + +interface IQux { + val qux: Int +} + +class CQux : IQux { + override val qux: Int get() = 0 +} + +interface IBarT { + val bar: T +} + +class CBarT : IBarT { + override val bar: T get() = null!! +} + +class Test1 : Final(), IFoo by CFoo() + +class Test2 : Final(), IBar by CBar() + +class Test3 : Final(), IQux by CQux() + +class Test4 : Derived(), IFoo by CFoo() + +class Test5 : Derived(), IBar by CBar() + +class Test6 : Derived(), IQux by CQux() + +class Test7 : Final(), IBarT by CBarT() + +class Test8 : Final(), IBarT by CBar() diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.txt b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.txt new file mode 100644 index 00000000000..756c51a07e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.txt @@ -0,0 +1,161 @@ +package + +public final class CBar : IBar { + public constructor CBar() + public open override /*1*/ val bar: kotlin.Int + 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 CBarT : IBarT { + public constructor CBarT() + public open override /*1*/ val bar: 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 +} + +public final class CFoo : IFoo { + public constructor CFoo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class CQux : IQux { + public constructor CQux() + public open override /*1*/ val qux: kotlin.Int + 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 Derived : Final { + public constructor Derived() + public final override /*1*/ /*fake_override*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Final { + public constructor Final() + public final val bar: kotlin.Int = 0 + public final var qux: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IBar { + public abstract val bar: kotlin.Int + 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 IBarT { + public abstract val bar: 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 +} + +public interface IFoo { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IQux { + public abstract val qux: kotlin.Int + 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 Test1 : Final, IFoo { + public constructor Test1() + public final override /*1*/ /*fake_override*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*delegation*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test2 : Final, IBar { + public constructor Test2() + public open override /*2*/ /*delegation*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test3 : Final, IQux { + public constructor Test3() + public final override /*1*/ /*fake_override*/ val bar: kotlin.Int + public open override /*2*/ /*delegation*/ val qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test4 : Derived, IFoo { + public constructor Test4() + public final override /*1*/ /*fake_override*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*delegation*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test5 : Derived, IBar { + public constructor Test5() + public open override /*2*/ /*delegation*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test6 : Derived, IQux { + public constructor Test6() + public final override /*1*/ /*fake_override*/ val bar: kotlin.Int + public open override /*2*/ /*delegation*/ val qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test7 : Final, IBarT { + public constructor Test7() + public open override /*2*/ /*delegation*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test8 : Final, IBarT { + public constructor Test8() + public open override /*2*/ /*delegation*/ val bar: kotlin.Int + public final override /*1*/ /*fake_override*/ var qux: kotlin.Int + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit + 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/delegation/clashes/propertyTypeMismatch.kt b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.kt new file mode 100644 index 00000000000..8318b2c5a67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.kt @@ -0,0 +1,57 @@ +interface IStr { + val foo: String +} + +class CStr : IStr { + override val foo: String get() = "" +} + +interface IInt { + val foo: Int +} + +class CInt : IInt { + override val foo: Int get() = 42 +} + +interface IAny { + val foo: Any +} + +class CAny : IAny { + override val foo: Any get() = null!! +} + +interface IGeneric { + val foo: T +} + +class CGeneric : IGeneric { + override val foo: T get() = null!! +} + +abstract class Test1 : IStr by CStr(), IInt + +abstract class Test2 : IStr, IInt by CInt() + +abstract class Test3 : IStr by CStr(), IInt by CInt() + +abstract class Test4 : IStr by CStr(), IGeneric + +abstract class Test5 : IStr by CStr(), IGeneric + +abstract class Test6 : IStr by CStr(), IGeneric + +abstract class Test7 : IGeneric by CGeneric(), IStr + +abstract class Test8 : IGeneric by CGeneric(), IInt + +// Can't test right now due to https://youtrack.jetbrains.com/issue/KT-10258 +// abstract class Test9 : IGeneric by CGeneric(), IGeneric + +abstract class Test10 : IInt by CInt(), IStr by CStr(), IAny by CAny() + +abstract class Test11 : IInt, IStr by CStr(), IAny by CAny() + +abstract class Test12 : IInt, IStr, IAny by CAny() + diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.txt b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.txt new file mode 100644 index 00000000000..1c35e6bad84 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.txt @@ -0,0 +1,149 @@ +package + +public final class CAny : IAny { + public constructor CAny() + public open override /*1*/ val foo: kotlin.Any + 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 CGeneric : IGeneric { + public constructor CGeneric() + public open override /*1*/ val foo: 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 +} + +public final class CInt : IInt { + public constructor CInt() + public open override /*1*/ val foo: kotlin.Int + 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 CStr : IStr { + public constructor CStr() + public open override /*1*/ val foo: 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 IAny { + public abstract val foo: kotlin.Any + 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 IGeneric { + public abstract val foo: 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 +} + +public interface IInt { + public abstract val foo: kotlin.Int + 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 IStr { + public abstract val foo: 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 abstract class Test1 : IStr, IInt { + public constructor Test1() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test10 : IInt, IStr, IAny { + public constructor Test10() + public open override /*3*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test11 : IInt, IStr, IAny { + public constructor Test11() + public open override /*3*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test12 : IInt, IStr, IAny { + public constructor Test12() + public open override /*3*/ /*delegation*/ val foo: kotlin.Any + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test2 : IStr, IInt { + public constructor Test2() + public open override /*2*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test3 : IStr, IInt { + public constructor Test3() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test4 : IStr, IGeneric { + public constructor Test4() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test5 : IStr, IGeneric { + public constructor Test5() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test6 : IStr, IGeneric { + public constructor Test6() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test7 : IGeneric, IStr { + public constructor Test7() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test8 : IGeneric, IInt { + public constructor Test8() + public open override /*2*/ /*delegation*/ val foo: kotlin.String + 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*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.kt b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.kt index be2f34ead7e..61082322924 100644 --- a/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.kt +++ b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.kt @@ -14,6 +14,14 @@ class CInt : IInt { override fun foo(): Int = 42 } +interface IAny { + fun foo(): Any +} + +class CAny : IAny { + override fun foo(): Any = null!! +} + interface IGeneric { fun foo(): T } @@ -24,21 +32,28 @@ class CGeneric : IGeneric { } } -abstract class Test1 : IStr by CStr(), IInt +abstract class Test1 : IStr by CStr(), IInt -abstract class Test2 : IStr, IInt by CInt() +abstract class Test2 : IStr, IInt by CInt() -abstract class Test3 : IStr by CStr(), IInt by CInt() +abstract class Test3 : IStr by CStr(), IInt by CInt() abstract class Test4 : IStr by CStr(), IGeneric abstract class Test5 : IStr by CStr(), IGeneric -abstract class Test6 : IStr by CStr(), IGeneric +abstract class Test6 : IStr by CStr(), IGeneric abstract class Test7 : IGeneric by CGeneric(), IStr -abstract class Test8 : IGeneric by CGeneric(), IInt +abstract class Test8 : IGeneric by CGeneric(), IInt -// Can't test right now due to https://youtrack.jetbrains.com/issue/KT-10258 +// Can't test due to https://youtrack.jetbrains.com/issue/KT-10258 // abstract class Test9 : IGeneric by CGeneric(), IGeneric + +abstract class Test10 : IInt by CInt(), IStr by CStr(), IAny by CAny() + +abstract class Test11 : IInt, IStr by CStr(), IAny by CAny() + +abstract class Test12 : IInt, IStr, IAny by CAny() + diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.txt b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.txt index 5939064ca10..a5dc0f124e8 100644 --- a/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.txt +++ b/compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.txt @@ -1,5 +1,13 @@ package +public final class CAny : IAny { + public constructor CAny() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun foo(): kotlin.Any + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + public final class CGeneric : IGeneric { public constructor CGeneric() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -24,6 +32,13 @@ public final class CStr : IStr { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +public interface IAny { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): kotlin.Any + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + public interface IGeneric { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(): T @@ -53,6 +68,30 @@ public abstract class Test1 : IStr, IInt { public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String } +public abstract class Test10 : IInt, IStr, IAny { + public constructor Test10() + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*3*/ /*delegation*/ fun foo(): kotlin.Int + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test11 : IInt, IStr, IAny { + public constructor Test11() + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*3*/ /*delegation*/ fun foo(): kotlin.String + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test12 : IInt, IStr, IAny { + public constructor Test12() + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*3*/ /*delegation*/ fun foo(): kotlin.Any + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} + public abstract class Test2 : IStr, IInt { public constructor Test2() public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.kt b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.kt new file mode 100644 index 00000000000..910d0b369e2 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.kt @@ -0,0 +1,29 @@ +interface IVar { + var foo: Int +} + +interface IDerived : IVar + +interface IVal { + val foo: Int +} + +class CVal : IVal { + override val foo: Int get() = 42 +} + +interface IValT { + val foo: T +} + +class CValT : IValT { + override val foo: T get() = null!! +} + +abstract class Test1 : IVar, IVal by CVal() + +abstract class Test2 : IVar, IValT by CValT() + +abstract class Test3 : IDerived, IVal by CVal() + +abstract class Test4 : IDerived, IValT by CValT() diff --git a/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.txt b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.txt new file mode 100644 index 00000000000..56c27f01449 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.txt @@ -0,0 +1,77 @@ +package + +public final class CVal : IVal { + public constructor CVal() + public open override /*1*/ val foo: kotlin.Int + 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 CValT : IValT { + public constructor CValT() + public open override /*1*/ val foo: 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 +} + +public interface IDerived : IVar { + public abstract override /*1*/ /*fake_override*/ var foo: kotlin.Int + 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 IVal { + public abstract val foo: kotlin.Int + 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 IValT { + public abstract val foo: 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 +} + +public interface IVar { + public abstract var foo: kotlin.Int + 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 abstract class Test1 : IVar, IVal { + public constructor Test1() + public open override /*2*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test2 : IVar, IValT { + public constructor Test2() + public open override /*2*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test3 : IDerived, IVal { + public constructor Test3() + public open override /*2*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} + +public abstract class Test4 : IDerived, IValT { + public constructor Test4() + public open override /*2*/ /*delegation*/ val foo: kotlin.Int + 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*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.kt index 32e735d2c36..bdb7e6e4220 100644 --- a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.kt +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.kt @@ -1,7 +1,5 @@ // FILE: InOut.k interface In -interface Out -interface Inv // FILE: J1.java public interface J1 { diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.txt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.txt index fa50898079b..742c794aadb 100644 --- a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.txt +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeIn.txt @@ -10,12 +10,6 @@ public interface In { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public interface Inv { - 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 J1 { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun foo(): In! @@ -51,12 +45,6 @@ public interface K2 { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } -public interface Out { - 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 TestJ1K1 : J1, K1 { public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract override /*2*/ /*fake_override*/ fun foo(): In diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.kt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.kt index dc217781eaa..fc4ef8d6d44 100644 --- a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.kt +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.kt @@ -34,4 +34,5 @@ interface Test7 : J, ILNS, IMLS interface Test8 : J, IMLNS, ILS interface Test9 : IMLNS, J, ILS -interface Test10 : IMLNS, ILS, J \ No newline at end of file +interface Test10 : IMLNS, ILS, J +interface Test11 : IMLNS, ILS \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.txt b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.txt index e035ef8128f..23305841a99 100644 --- a/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.txt +++ b/compiler/testData/diagnostics/tests/override/clashesOnInheritance/flexibleReturnTypeList.txt @@ -51,6 +51,13 @@ public interface Test10 : IMLNS, ILS, J { public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String } +public interface Test11 : IMLNS, ILS { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*2*/ /*fake_override*/ fun foo(): kotlin.MutableList + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + public interface Test2 : J, ILNS { public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract override /*2*/ /*fake_override*/ fun foo(): kotlin.List diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 812e028b794..db44933a8e9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -4763,11 +4763,29 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegation/clashes"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("finalMemberOverridden.kt") + public void testFinalMemberOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/clashes/finalMemberOverridden.kt"); + doTest(fileName); + } + + @TestMetadata("propertyTypeMismatch.kt") + public void testPropertyTypeMismatch() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/clashes/propertyTypeMismatch.kt"); + doTest(fileName); + } + @TestMetadata("returnTypeMismatch.kt") public void testReturnTypeMismatch() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/clashes/returnTypeMismatch.kt"); doTest(fileName); } + + @TestMetadata("varOverriddenByVal.kt") + public void testVarOverriddenByVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/clashes/varOverriddenByVal.kt"); + doTest(fileName); + } } }