diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index a9eafc8dd7b..4df7f90f70d 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -10919,6 +10919,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); } + @Test + @TestMetadata("subtypingBetweenContextReceivers.kt") + public void testSubtypingBetweenContextReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt"); + } + @Test @TestMetadata("superWithContext.kt") public void testSuperWithContext() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 66774a47b76..eaa22aef3d3 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -10919,6 +10919,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); } + @Test + @TestMetadata("subtypingBetweenContextReceivers.kt") + public void testSubtypingBetweenContextReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt"); + } + @Test @TestMetadata("superWithContext.kt") public void testSuperWithContext() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 8b0790fd255..70805a36d75 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -10919,6 +10919,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); } + @Test + @TestMetadata("subtypingBetweenContextReceivers.kt") + public void testSubtypingBetweenContextReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt"); + } + @Test @TestMetadata("superWithContext.kt") public void testSuperWithContext() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 852ef6c393b..87da7df9eb1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -1308,6 +1308,7 @@ public interface Errors { DiagnosticFactory1 MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 SUBTYPING_BETWEEN_CONTEXT_RECEIVERS = DiagnosticFactory0.create(ERROR); // Error sets ImmutableSet> UNRESOLVED_REFERENCE_DIAGNOSTICS = ImmutableSet.of( 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 0171c9f4235..a0d53a9afea 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -1120,6 +1120,7 @@ public class DefaultErrorMessages { MAP.put(MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER, "Multiple arguments applicable for context receiver: {0}", TO_STRING); MAP.put(AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER, "With implicit context receiver, call is ambiguous. Specify the receiver explicitly"); MAP.put(UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL, "To use contextual declarations, specify the `-Xcontext-receivers` compiler option"); + MAP.put(SUBTYPING_BETWEEN_CONTEXT_RECEIVERS, "Subtyping relation between context receivers is prohibited"); MAP.setImmutable(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ContextReceiversUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ContextReceiversUtil.kt new file mode 100644 index 00000000000..b94401e43e7 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ContextReceiversUtil.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.resolve + +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.psi.KtContextReceiverList +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker +import org.jetbrains.kotlin.types.typeUtil.containsTypeParameter +import org.jetbrains.kotlin.types.typeUtil.isTypeParameter +import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections +import org.jetbrains.kotlin.types.typeUtil.supertypes + +fun checkContextReceiversAreEnabled( + trace: BindingTrace, + languageVersionSettings: LanguageVersionSettings, + contextReceiverList: KtContextReceiverList +) { + if (!languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) { + trace.report( + Errors.UNSUPPORTED_FEATURE.on( + contextReceiverList, + LanguageFeature.ContextReceivers to languageVersionSettings + ) + ) + } +} + +fun checkSubtypingBetweenContextReceivers( + trace: BindingTrace, + contextReceiverList: KtContextReceiverList, + contextReceiverTypes: List +) { + fun KotlinType.prepared(): KotlinType = when { + isTypeParameter() -> supertypes().first() + containsTypeParameter() -> replaceArgumentsWithStarProjections() + else -> this + } + for (i in 0 until contextReceiverTypes.lastIndex) { + val contextReceiverType = contextReceiverTypes[i].prepared() + for (j in (i + 1) until contextReceiverTypes.size) { + val anotherContextReceiverType = contextReceiverTypes[j].prepared() + if (NewKotlinTypeChecker.Default.isSubtypeOf(contextReceiverType, anotherContextReceiverType) || + NewKotlinTypeChecker.Default.isSubtypeOf(anotherContextReceiverType, contextReceiverType) + ) { + trace.report(Errors.SUBTYPING_BETWEEN_CONTEXT_RECEIVERS.on(contextReceiverList)) + return + } + } + } +} + diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt index 3249a9b419e..c099651cf65 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/PlatformConfiguratorBase.kt @@ -48,6 +48,7 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf( SuspendFunctionAsSupertypeChecker, EnumCompanionInEnumConstructorCallChecker, ContextualDeclarationChecker, + SubtypingBetweenContextReceiversChecker, ValueParameterUsageInDefaultArgumentChecker, CyclicAnnotationsChecker, ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index b7d99a4f1bc..2f791a04459 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -368,10 +368,12 @@ class TypeResolver( val contextReceiverList = type.contextReceiverList val contextReceiversTypes = if (contextReceiverList != null) { - checkContextReceiversAreEnabled(contextReceiverList) - contextReceiverList.typeReferences().map { typeRef -> + checkContextReceiversAreEnabled(c.trace, languageVersionSettings, contextReceiverList) + val types = contextReceiverList.typeReferences().map { typeRef -> resolveType(c.noBareTypes(), typeRef) } + checkSubtypingBetweenContextReceivers(c.trace, contextReceiverList, types) + types } else emptyList() val parameterDescriptors = resolveParametersOfFunctionType(type.parameters) @@ -454,7 +456,7 @@ class TypeResolver( } override fun visitContextReceiverList(contextReceiverList: KtContextReceiverList) { - checkContextReceiversAreEnabled(contextReceiverList) + checkContextReceiversAreEnabled(c.trace, languageVersionSettings, contextReceiverList) } override fun visitDynamicType(type: KtDynamicType) { @@ -496,17 +498,6 @@ class TypeResolver( c.trace.report(Errors.UNSUPPORTED.on(it, "val or var on parameter in function type")) } } - - private fun checkContextReceiversAreEnabled(contextReceiverList: KtContextReceiverList) { - if (!languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) { - c.trace.report( - UNSUPPORTED_FEATURE.on( - contextReceiverList, - LanguageFeature.ContextReceivers to languageVersionSettings - ) - ) - } - } }) return result ?: type(ErrorUtils.createErrorType(ErrorTypeKind.NO_TYPE_SPECIFIED, typeElement?.getDebugText() ?: "unknown element")) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ContextualDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ContextualDeclarationChecker.kt index 5019143c0ae..226d91640fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ContextualDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ContextualDeclarationChecker.kt @@ -6,11 +6,14 @@ package org.jetbrains.kotlin.resolve.checkers import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.isContextualDeclaration +import org.jetbrains.kotlin.resolve.checkContextReceiversAreEnabled +import org.jetbrains.kotlin.resolve.checkSubtypingBetweenContextReceivers object ContextualDeclarationChecker : DeclarationChecker { override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { @@ -19,12 +22,23 @@ object ContextualDeclarationChecker : DeclarationChecker { } if (declaration.isContextualDeclaration()) { val contextReceiverList = declaration.findDescendantOfType() ?: return - context.trace.report( - Errors.UNSUPPORTED_FEATURE.on( - contextReceiverList, LanguageFeature.ContextReceivers to context.languageVersionSettings - ) - ) + checkContextReceiversAreEnabled(context.trace, context.languageVersionSettings, contextReceiverList) return } } +} + +object SubtypingBetweenContextReceiversChecker : DeclarationChecker { + override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers) || !declaration.isContextualDeclaration()) { + return + } + val contextReceivers = when (descriptor) { + is CallableDescriptor -> descriptor.contextReceiverParameters + is ClassDescriptor -> descriptor.contextReceivers + else -> return + } + val contextReceiverList = declaration.findDescendantOfType() ?: return + checkSubtypingBetweenContextReceivers(context.trace, contextReceiverList, contextReceivers.map { it.type }) + } } \ No newline at end of file diff --git a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/substitutedContextReceivers.kt b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/substitutedContextReceivers.kt index 940d2e04e7c..e4f987d9589 100644 --- a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/substitutedContextReceivers.kt +++ b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/substitutedContextReceivers.kt @@ -3,7 +3,7 @@ class Box(val x: E) -class A { +class A { context(Box, Y) fun foo(): String = x.toString() + this@Y.toString() @@ -12,7 +12,7 @@ class A { } context(Box, Y) -fun bar(): String = x.toString() + this@Y.toString() +fun bar(): String = x.toString() + this@Y.toString() fun box(): String { return with(Box("OK")) { diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.fir.kt new file mode 100644 index 00000000000..11692f55f67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.fir.kt @@ -0,0 +1,221 @@ +// !DIAGNOSTICS: -UNCHECKED_CAST +// !LANGUAGE: +ContextReceivers + +interface A +interface B : A +typealias C = B + +interface Inv +interface Cov + +// Functions + +context(A, A) +fun f1() {} + +context(A, B) +fun f2() {} + +context(A, C) +fun f3() {} + +context(B, C) +fun f4() {} + +context(C, C) +fun f5() {} + +context(A, A, A) +fun f6() {} + +context(Inv, Inv) +fun f7() {} + +context(Inv, Inv) +fun f8() {} + +context(Inv, Inv) +fun f9() {} + +context(Cov, Cov) +fun f10() {} + +context(Cov, Cov) +fun f11() {} + +context(T, A) +fun f12() {} + +// Classes + +context(A, A) +class C1 { + context(A, A) + val p: Any get() = 42 + + context(A, A) + fun m() {} +} + +context(A, B) +class C2 { + context(A, B) + val p: Any get() = 42 + + context(A, B) + fun m() {} +} + +context(A, C) +class C3 { + context(A, C) + val p: Any get() = 42 + + context(A, C) + fun m() {} +} + +context(B, C) +class C4 { + context(B, C) + val p: Any get() = 42 + + context(B, C) + fun m() {} +} + +context(C, C) +class C5 { + context(C, C) + val p: Any get() = 42 + + context(C, C) + fun m() {} +} + +context(A, A, A) +class C6 { + context(A, A, A) + val p: Any get() = 42 + + context(A, A, A) + fun m() {} +} + +context(Inv, Inv) +class C7 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Inv, Inv) +class C8 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Inv, Inv) +class C9 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Cov, Cov) +class C10 { + context(Cov, Cov) + val p: Any get() = 42 + + context(Cov, Cov) + fun m() {} +} + +context(Cov, Cov) +class C11 { + context(Cov, Cov) + val p: Any get() = 42 + + context(Cov, Cov) + fun m() {} +} + +context(T, A) +class C12 { + context(T, A) + val p: Any get() = 42 + + context(T, A) + fun m() {} +} + +// Properties + +context(A, A) +val p1: Any? + get() { return null } + +context(A, B) +val p2: Any? + get() { return null } + +context(A, C) +val p3: Any? + get() { return null } + +context(B, C) +val p4: Any? + get() { return null } + +context(C, C) +val p5: Any? + get() { return null } + +context(A, A, A) +val p6: Any? + get() { return null } + +context(Inv, Inv) +val p7: Any? + get() { return null } + +context(Inv, Inv) +val p8: Any? + get() { return null } + +context(Inv, Inv) +val p9: Any? + get() { return null } + +context(Cov, Cov) +val p10: Any? + get() { return null } + +context(Cov, Cov) +val p11: Any? + get() { return null } + +context(T, A) +val p12: Any? + get() { return null } + +// Function types + +// Function types are processed with the same function that is used for checking contextual declarations +// So we check here only one simple case: `context(A, B)` + +context(A, B) +fun f(g: context(A, B) () -> Unit, value: Any): context(A, B) () -> Unit { + return value as (context(A, B) () -> Unit) +} + +fun test() { + val lf: context(A, B) () -> Unit = { } +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt new file mode 100644 index 00000000000..05908907248 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt @@ -0,0 +1,221 @@ +// !DIAGNOSTICS: -UNCHECKED_CAST +// !LANGUAGE: +ContextReceivers + +interface A +interface B : A +typealias C = B + +interface Inv +interface Cov + +// Functions + +context(A, A) +fun f1() {} + +context(A, B) +fun f2() {} + +context(A, C) +fun f3() {} + +context(B, C) +fun f4() {} + +context(C, C) +fun f5() {} + +context(A, A, A) +fun f6() {} + +context(Inv, Inv) +fun f7() {} + +context(Inv, Inv) +fun f8() {} + +context(Inv, Inv) +fun f9() {} + +context(Cov, Cov) +fun f10() {} + +context(Cov, Cov) +fun f11() {} + +context(T, A) +fun f12() {} + +// Classes + +context(A, A) +class C1 { + context(A, A) + val p: Any get() = 42 + + context(A, A) + fun m() {} +} + +context(A, B) +class C2 { + context(A, B) + val p: Any get() = 42 + + context(A, B) + fun m() {} +} + +context(A, C) +class C3 { + context(A, C) + val p: Any get() = 42 + + context(A, C) + fun m() {} +} + +context(B, C) +class C4 { + context(B, C) + val p: Any get() = 42 + + context(B, C) + fun m() {} +} + +context(C, C) +class C5 { + context(C, C) + val p: Any get() = 42 + + context(C, C) + fun m() {} +} + +context(A, A, A) +class C6 { + context(A, A, A) + val p: Any get() = 42 + + context(A, A, A) + fun m() {} +} + +context(Inv, Inv) +class C7 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Inv, Inv) +class C8 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Inv, Inv) +class C9 { + context(Inv, Inv) + val p: Any get() = 42 + + context(Inv, Inv) + fun m() {} +} + +context(Cov, Cov) +class C10 { + context(Cov, Cov) + val p: Any get() = 42 + + context(Cov, Cov) + fun m() {} +} + +context(Cov, Cov) +class C11 { + context(Cov, Cov) + val p: Any get() = 42 + + context(Cov, Cov) + fun m() {} +} + +context(T, A) +class C12 { + context(T, A) + val p: Any get() = 42 + + context(T, A) + fun m() {} +} + +// Properties + +context(A, A) +val p1: Any? + get() { return null } + +context(A, B) +val p2: Any? + get() { return null } + +context(A, C) +val p3: Any? + get() { return null } + +context(B, C) +val p4: Any? + get() { return null } + +context(C, C) +val p5: Any? + get() { return null } + +context(A, A, A) +val p6: Any? + get() { return null } + +context(Inv, Inv) +val p7: Any? + get() { return null } + +context(Inv, Inv) +val p8: Any? + get() { return null } + +context(Inv, Inv) +val p9: Any? + get() { return null } + +context(Cov, Cov) +val p10: Any? + get() { return null } + +context(Cov, Cov) +val p11: Any? + get() { return null } + +context(T, A) +val p12: Any? + get() { return null } + +// Function types + +// Function types are processed with the same function that is used for checking contextual declarations +// So we check here only one simple case: `context(A, B)` + +context(A, B) +fun f(g: context(A, B) () -> Unit, value: Any): context(A, B) () -> Unit { + return value as (context(A, B) () -> Unit) +} + +fun test() { + val lf: context(A, B) () -> Unit = { } +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.txt new file mode 100644 index 00000000000..ec64eec02d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.txt @@ -0,0 +1,161 @@ +package + +context(A, A) public val p1: kotlin.Any? +context(Cov, Cov) public val p10: kotlin.Any? +context(Cov, Cov) public val p11: kotlin.Any? +context(T, A) public val p12: kotlin.Any? +context(A, B) public val p2: kotlin.Any? +context(A, C /* = B */) public val p3: kotlin.Any? +context(B, C /* = B */) public val p4: kotlin.Any? +context(C /* = B */, C /* = B */) public val p5: kotlin.Any? +context(A, A, A) public val p6: kotlin.Any? +context(Inv, Inv) public val p7: kotlin.Any? +context(Inv, Inv) public val p8: kotlin.Any? +context(Inv, Inv) public val p9: kotlin.Any? +context(A, B) public fun f(/*0*/ g: context(A, B) () -> kotlin.Unit, /*1*/ value: kotlin.Any): context(A, B) () -> kotlin.Unit +context(A, A) public fun f1(): kotlin.Unit +context(Cov, Cov) public fun f10(): kotlin.Unit +context(Cov, Cov) public fun f11(): kotlin.Unit +context(T, A) public fun f12(): kotlin.Unit +context(A, B) public fun f2(): kotlin.Unit +context(A, C /* = B */) public fun f3(): kotlin.Unit +context(B, C /* = B */) public fun f4(): kotlin.Unit +context(C /* = B */, C /* = B */) public fun f5(): kotlin.Unit +context(A, A, A) public fun f6(): kotlin.Unit +context(Inv, Inv) public fun f7(): kotlin.Unit +context(Inv, Inv) public fun f8(): kotlin.Unit +context(Inv, Inv) public fun f9(): kotlin.Unit +public fun test(): kotlin.Unit + +public interface A { + 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 B : A { + 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 +} + +context(A, A) public final class C1 { + public constructor C1() + context(A, A) public final val p: 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 + context(A, A) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(Cov, Cov) public final class C10 { + public constructor C10() + context(Cov, Cov) public final val p: 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 + context(Cov, Cov) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(Cov, Cov) public final class C11 { + public constructor C11() + context(Cov, Cov) public final val p: 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 + context(Cov, Cov) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(T, A) public final class C12 { + public constructor C12() + context(T, A) public final val p: 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 + context(T, A) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(A, B) public final class C2 { + public constructor C2() + context(A, B) public final val p: 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 + context(A, B) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(A, C /* = B */) public final class C3 { + public constructor C3() + context(A, C /* = B */) public final val p: 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 + context(A, C /* = B */) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(B, C /* = B */) public final class C4 { + public constructor C4() + context(B, C /* = B */) public final val p: 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 + context(B, C /* = B */) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(C /* = B */, C /* = B */) public final class C5 { + public constructor C5() + context(C /* = B */, C /* = B */) public final val p: 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 + context(C /* = B */, C /* = B */) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(A, A, A) public final class C6 { + public constructor C6() + context(A, A, A) public final val p: 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 + context(A, A, A) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(Inv, Inv) public final class C7 { + public constructor C7() + context(Inv, Inv) public final val p: 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 + context(Inv, Inv) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(Inv, Inv) public final class C8 { + public constructor C8() + context(Inv, Inv) public final val p: 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 + context(Inv, Inv) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +context(Inv, Inv) public final class C9 { + public constructor C9() + context(Inv, Inv) public final val p: 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 + context(Inv, Inv) public final fun m(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Cov { + 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 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 typealias C = B diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index cb5f9f704ad..c0b2f19c565 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -10925,6 +10925,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); } + @Test + @TestMetadata("subtypingBetweenContextReceivers.kt") + public void testSubtypingBetweenContextReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/subtypingBetweenContextReceivers.kt"); + } + @Test @TestMetadata("superWithContext.kt") public void testSuperWithContext() throws Exception {