diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index f2dd3be540d..45870787c88 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -574,6 +574,7 @@ public interface Errors { DiagnosticFactory0 ABSTRACT_SUPER_CALL = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NOT_A_SUPERTYPE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER = DiagnosticFactory0.create(WARNING); + DiagnosticFactory1 QUALIFIED_SUPERTYPE_EXTENDED_BY_OTHER_SUPERTYPE = DiagnosticFactory1.create(ERROR); // Conventions 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 225cd067a82..a3d11741e88 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -330,6 +330,7 @@ public class DefaultErrorMessages { MAP.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly"); MAP.put(NOT_A_SUPERTYPE, "Not an immediate supertype"); MAP.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, "Type arguments do not need to be specified in a 'super' qualifier"); + MAP.put(QUALIFIED_SUPERTYPE_EXTENDED_BY_OTHER_SUPERTYPE, "Explicitly qualified supertype is extended by another supertype ''{0}''", RENDER_TYPE); MAP.put(USELESS_CAST, "No cast needed"); MAP.put(CAST_NEVER_SUCCEEDS, "This cast can never succeed"); MAP.put(DYNAMIC_NOT_ALLOWED, "Dynamic types are not allowed in this position"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 3c962b2ea24..1806780ba48 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -479,6 +479,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { else if (redundantTypeArguments != null) { context.trace.report(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER.on(redundantTypeArguments)); } + + if (result != null && (validClassifier || validType)) { + checkResolvedExplicitlyQualifiedSupertype(context.trace, result, supertypes, superTypeQualifier); + } } else { if (UnqualifiedSuperKt.isPossiblyAmbiguousUnqualifiedSuper(expression, supertypes)) { @@ -522,6 +526,27 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return result; } + private static void checkResolvedExplicitlyQualifiedSupertype( + @NotNull BindingTrace trace, + @NotNull KotlinType result, + @NotNull Collection supertypes, + @NotNull KtTypeReference superTypeQualifier + ) { + if (supertypes.size() > 1) { + ClassifierDescriptor resultClassifierDescriptor = result.getConstructor().getDeclarationDescriptor(); + for (KotlinType otherSupertype : supertypes) { + ClassifierDescriptor otherSupertypeClassifierDescriptor = otherSupertype.getConstructor().getDeclarationDescriptor(); + if (otherSupertypeClassifierDescriptor == resultClassifierDescriptor) { + continue; + } + if (KotlinTypeChecker.DEFAULT.isSubtypeOf(otherSupertype, result)) { + trace.report(QUALIFIED_SUPERTYPE_EXTENDED_BY_OTHER_SUPERTYPE.on(superTypeQualifier, otherSupertype)); + break; + } + } + } + } + @NotNull // No class receivers private LabelResolver.LabeledReceiverResolutionResult resolveToReceiver( KtInstanceExpressionWithLabel expression, diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt new file mode 100644 index 00000000000..0086dfe65c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt @@ -0,0 +1,19 @@ +interface IBase { + fun foo() {} + fun bar() {} +} + +interface IDerived : IBase { + override fun foo() {} + fun qux() {} +} + +class Test : IDerived, IBase { + fun test() { + super<IBase>.foo() + super<IBase>.bar() + super.foo() + super.bar() + super.qux() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.txt b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.txt new file mode 100644 index 00000000000..5d711a180c1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.txt @@ -0,0 +1,29 @@ +package + +public interface IBase { + public open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IDerived : IBase { + public open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit + 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 fun qux(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Test : IDerived, IBase { + public constructor Test() + public open override /*2*/ /*fake_override*/ fun bar(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun foo(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun qux(): kotlin.Unit + public final fun test(): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.kt b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.kt new file mode 100644 index 00000000000..23bacc0afcd --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.kt @@ -0,0 +1,29 @@ +interface IBase { + fun foo() {} + fun bar() {} +} + +interface IDerived1 : IBase { + override fun foo() {} + fun qux() {} +} + +interface IDerived2 : IBase { + override fun foo() {} +} + +class Test : IDerived1, IBase, IDerived2 { + override fun foo() {} + + fun test() { + super<IBase>.foo() + super<IBase>.bar() + + super.foo() + super.bar() + super.qux() + + super.foo() + super.bar() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.txt b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.txt new file mode 100644 index 00000000000..52ab06369a7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.txt @@ -0,0 +1,37 @@ +package + +public interface IBase { + public open fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IDerived1 : IBase { + public open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit + 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 fun qux(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IDerived2 : IBase { + public open override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit + 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 Test : IDerived1, IBase, IDerived2 { + public constructor Test() + public open override /*3*/ /*fake_override*/ fun bar(): kotlin.Unit + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*3*/ fun foo(): kotlin.Unit + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun qux(): kotlin.Unit + public final fun test(): kotlin.Unit + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 3457caee061..3469cbcfa98 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19365,12 +19365,24 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("genericQualifiedSuperOverridden.kt") + public void testGenericQualifiedSuperOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/genericQualifiedSuperOverridden.kt"); + doTest(fileName); + } + @TestMetadata("notAccessibleSuperInTrait.kt") public void testNotAccessibleSuperInTrait() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/notAccessibleSuperInTrait.kt"); doTest(fileName); } + @TestMetadata("qualifiedSuperOverridden.kt") + public void testQualifiedSuperOverridden() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/qualifiedSuperOverridden.kt"); + doTest(fileName); + } + @TestMetadata("QualifiedThis.kt") public void testQualifiedThis() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.kt"); diff --git a/js/js.translator/testData/superCall/cases/traitSuperCall.kt b/js/js.translator/testData/superCall/cases/traitSuperCall.kt index 9dd4e65f6d7..317a2a617db 100644 --- a/js/js.translator/testData/superCall/cases/traitSuperCall.kt +++ b/js/js.translator/testData/superCall/cases/traitSuperCall.kt @@ -5,12 +5,12 @@ interface A { fun foo(t: Int): Int = t + 1 } -interface B : A { - override fun bar(): Int = 3 +interface B { + fun foo(t: Int): Int = t + fun bar(): Int = 3 } class C : B, A { - override fun bar(): Int { return super.bar() + super.bar() } @@ -23,7 +23,7 @@ class C : B, A { fun box(): String { val c = C() - if (c.foo(3) != 5) return "Trait super call fail. c.foo(3) is ${c.foo(3)}" - if (c.bar() != 5) return "Trait super call fail. c.bar() is ${c.bar()}" + if (c.foo(3) != 5) return "Interface super call fail. c.foo(3) is ${c.foo(3)}" + if (c.bar() != 5) return "Interface super call fail. c.bar() is ${c.bar()}" return "OK" } \ No newline at end of file