From c34fe8d547d084683a9e0b9b3334f681233f44a9 Mon Sep 17 00:00:00 2001 From: Anastasiya Shadrina Date: Mon, 15 Feb 2021 18:54:11 +0700 Subject: [PATCH] [FE] Implement temporary resolution algorithm --- ...irOldFrontendDiagnosticsTestGenerated.java | 76 +++++++++++++++++-- .../jetbrains/kotlin/diagnostics/Errors.java | 3 + .../rendering/DefaultErrorMessages.java | 2 + .../DiagnosticReporterByTrackingStrategy.kt | 9 +++ .../calls/model/DelegatingResolvedCall.java | 6 ++ .../resolve/calls/model/ResolvedCall.java | 4 + .../resolve/calls/model/ResolvedCallImpl.java | 6 ++ .../calls/components/ResolutionParts.kt | 66 +++++++++++++--- .../calls/model/KotlinCallDiagnostics.kt | 7 ++ .../resolve/calls/model/ResolutionAtoms.kt | 1 + .../resolve/calls/model/ResolvedCallAtoms.kt | 1 + .../extensions/contextReceivers/dp.fir.kt | 20 +++++ .../tests/extensions/contextReceivers/dp.kt | 20 +++++ .../tests/extensions/contextReceivers/dp.txt | 13 ++++ .../insideDeclaration.fir.kt} | 0 .../insideDeclaration.kt} | 0 .../insideDeclaration.txt} | 0 .../extensions/contextReceivers/lazy.fir.kt | 48 ++++++++++++ .../tests/extensions/contextReceivers/lazy.kt | 48 ++++++++++++ .../extensions/contextReceivers/lazy.txt | 12 +++ .../contextReceivers/manyReceivers.fir.kt | 35 +++++++++ .../contextReceivers/manyReceivers.kt | 35 +++++++++ .../contextReceivers/manyReceivers.txt | 28 +++++++ .../noExplicitReceiver.fir.kt | 18 +++++ .../contextReceivers/noExplicitReceiver.kt | 18 +++++ .../contextReceivers/noExplicitReceiver.txt | 27 +++++++ .../extensions/contextReceivers/plusMatrix.kt | 15 ++++ .../contextReceivers/plusMatrix.txt | 18 +++++ .../contextReceivers/typeParameterized.fir.kt | 11 +++ .../contextReceivers/typeParameterized.kt | 11 +++ .../contextReceivers/typeParameterized.txt | 19 +++++ .../typeParameterizedList.fir.kt | 17 +++++ .../contextReceivers/typeParameterizedList.kt | 17 +++++ .../typeParameterizedList.txt | 12 +++ .../withExplicitReceiver.fir.kt | 18 +++++ .../contextReceivers/withExplicitReceiver.kt | 18 +++++ .../contextReceivers/withExplicitReceiver.txt | 25 ++++++ .../withExplicitReceiverError.fir.kt | 18 +++++ .../withExplicitReceiverError.kt | 18 +++++ .../withExplicitReceiverError.txt | 25 ++++++ .../test/runners/DiagnosticTestGenerated.java | 76 +++++++++++++++++-- .../org/jetbrains/kotlin/types/TypeUtils.kt | 2 + .../kotlin/js/translate/utils/utils.kt | 1 + 43 files changed, 800 insertions(+), 24 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.txt rename compiler/testData/diagnostics/tests/extensions/{contextReceiver.fir.kt => contextReceivers/insideDeclaration.fir.kt} (100%) rename compiler/testData/diagnostics/tests/extensions/{contextReceiver.kt => contextReceivers/insideDeclaration.kt} (100%) rename compiler/testData/diagnostics/tests/extensions/{contextReceiver.txt => contextReceivers/insideDeclaration.txt} (100%) create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.txt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt create mode 100644 compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.txt 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 08e26278934..9fc21e85895 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 @@ -10471,12 +10471,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/extensions/classObject.kt"); } - @Test - @TestMetadata("contextReceiver.kt") - public void testContextReceiver() throws Exception { - runTest("compiler/testData/diagnostics/tests/extensions/contextReceiver.kt"); - } - @Test @TestMetadata("ExtensionFunctions.kt") public void testExtensionFunctions() throws Exception { @@ -10572,6 +10566,76 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti public void testVariableInvoke() throws Exception { runTest("compiler/testData/diagnostics/tests/extensions/variableInvoke.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/extensions/contextReceivers") + @TestDataPath("$PROJECT_ROOT") + public class ContextReceivers { + @Test + public void testAllFilesPresentInContextReceivers() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/extensions/contextReceivers"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("dp.kt") + public void testDp() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt"); + } + + @Test + @TestMetadata("insideDeclaration.kt") + public void testInsideDeclaration() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.kt"); + } + + @Test + @TestMetadata("lazy.kt") + public void testLazy() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt"); + } + + @Test + @TestMetadata("manyReceivers.kt") + public void testManyReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt"); + } + + @Test + @TestMetadata("noExplicitReceiver.kt") + public void testNoExplicitReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt"); + } + + @Test + @TestMetadata("plusMatrix.kt") + public void testPlusMatrix() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); + } + + @Test + @TestMetadata("typeParameterized.kt") + public void testTypeParameterized() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt"); + } + + @Test + @TestMetadata("typeParameterizedList.kt") + public void testTypeParameterizedList() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt"); + } + + @Test + @TestMetadata("withExplicitReceiver.kt") + public void testWithExplicitReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt"); + } + + @Test + @TestMetadata("withExplicitReceiverError.kt") + public void testWithExplicitReceiverError() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt"); + } + } } @Nested diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 8b5d322ece2..31639987250 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -1194,6 +1194,9 @@ public interface Errors { DiagnosticFactory1 ERROR_IN_CONTRACT_DESCRIPTION = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 CONTRACT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR); + // Context receivers + DiagnosticFactory1 NO_CONTEXT_RECEIVER = DiagnosticFactory1.create(ERROR); + // Error sets ImmutableSet> UNRESOLVED_REFERENCE_DIAGNOSTICS = ImmutableSet.of( UNRESOLVED_REFERENCE, NAMED_PARAMETER_NOT_FOUND, UNRESOLVED_REFERENCE_WRONG_RECEIVER); 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 54234e1e70f..63b3968bd0d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -1086,6 +1086,8 @@ public class DefaultErrorMessages { MAP.put(ERROR_IN_CONTRACT_DESCRIPTION, "Error in contract description: {0}", TO_STRING); MAP.put(CONTRACT_NOT_ALLOWED, "{0}", TO_STRING); + MAP.put(NO_CONTEXT_RECEIVER, "No required context receiver found: {0}", TO_STRING); + MAP.setImmutable(); for (Field field : Errors.class.getFields()) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index a00b4793e10..b108868716e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -93,6 +93,15 @@ class DiagnosticReporterByTrackingStrategy( ) ) } + NoContextReceiver::class.java -> { + val callElement = psiKotlinCall.psiCall.callElement + trace.report( + NO_CONTEXT_RECEIVER.on( + callElement, + (diagnostic as NoContextReceiver).receiverDescriptor.value.toString() + ) + ) + } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/DelegatingResolvedCall.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/DelegatingResolvedCall.java index f5c2c1a08fd..bc9274f0173 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/DelegatingResolvedCall.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/DelegatingResolvedCall.java @@ -74,6 +74,12 @@ public abstract class DelegatingResolvedCall imple return resolvedCall.getDispatchReceiver(); } + @NotNull + @Override + public List getContextReceivers() { + return resolvedCall.getContextReceivers(); + } + @NotNull @Override public ExplicitReceiverKind getExplicitReceiverKind() { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCall.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCall.java index 21782f3044b..145119a01b5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCall.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCall.java @@ -69,6 +69,10 @@ public interface ResolvedCall { @Nullable ReceiverValue getDispatchReceiver(); + /** If the target was a function or property with context receivers, this is the value for its context receiver parameters */ + @NotNull + List getContextReceivers(); + /** Determines whether receiver argument or this object is substituted for explicit receiver */ @NotNull ExplicitReceiverKind getExplicitReceiverKind(); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java index 261a6b178ab..c1d9d257c77 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java @@ -288,6 +288,12 @@ public class ResolvedCallImpl implements MutableRe return dispatchReceiver; } + @NotNull + @Override + public List getContextReceivers() { + return Collections.emptyList(); + } + @Override @NotNull public ExplicitReceiverKind getExplicitReceiverKind() { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index c7e55049efa..735dfc691d6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -10,6 +10,8 @@ import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor +import org.jetbrains.kotlin.resolve.calls.components.CheckReceivers.candidateDescriptor +import org.jetbrains.kotlin.resolve.calls.components.CheckReceivers.checkReceiver import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate @@ -24,13 +26,15 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.* import org.jetbrains.kotlin.resolve.calls.tower.InfixCallNoInfixModifier import org.jetbrains.kotlin.resolve.calls.tower.InvokeConventionCallNoOperatorModifier import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError +import org.jetbrains.kotlin.resolve.scopes.LexicalScope +import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo +import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeConstructorMarker import org.jetbrains.kotlin.types.model.typeConstructor -import org.jetbrains.kotlin.types.typeUtil.contains -import org.jetbrains.kotlin.types.typeUtil.makeNotNullable -import org.jetbrains.kotlin.types.typeUtil.makeNullable +import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible @@ -680,22 +684,60 @@ internal object CheckReceivers : ResolutionPart() { } override fun ResolutionCandidate.process(workIndex: Int) { - if (workIndex == 0) { - checkReceiver( + when (workIndex) { + 0 -> checkReceiver( resolvedCall.dispatchReceiverArgument, candidateDescriptor.dispatchReceiverParameter, shouldCheckImplicitInvoke = true, ) - } else { - checkReceiver( - resolvedCall.extensionReceiverArgument, - candidateDescriptor.extensionReceiverParameter, - shouldCheckImplicitInvoke = false, // reproduce old inference behaviour - ) + 1 -> { + checkReceiver( + resolvedCall.extensionReceiverArgument, + candidateDescriptor.extensionReceiverParameter, + shouldCheckImplicitInvoke = false, // reproduce old inference behaviour + ) + } + else -> { + resolvedCall.contextReceiversArguments = searchForAdditionalReceivers() ?: return + for (i in resolvedCall.contextReceiversArguments.indices) { + checkReceiver( + resolvedCall.contextReceiversArguments[i], + candidateDescriptor.contextReceiverParameters[i], + shouldCheckImplicitInvoke = false + ) + } + } } } - override fun ResolutionCandidate.workCount() = 2 + override fun ResolutionCandidate.workCount() = 3 + + private fun ResolutionCandidate.searchForAdditionalReceivers(): List? { + val result = mutableListOf() + val candidateReceivers = scopeTower.lexicalScope.parentsWithSelf + .flatMap { if (it is LexicalScope) scopeTower.getImplicitReceivers(it) else emptyList() } + + fun KotlinType.prepared(): KotlinType = if (containsTypeParameter()) replaceArgumentsWithStarProjections() else this + + for (receiver in candidateDescriptor.contextReceiverParameters) { + val expectedReceiverType = receiver.type + val expectedReceiverTypeClosestBound = + if (expectedReceiverType.isTypeParameter()) expectedReceiverType.supertypes().first() + else expectedReceiverType + val selectedCandidate = candidateReceivers.firstOrNull { candidateReceiver -> + val candidateReceiverType = candidateReceiver.receiverValue.type + org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker.Default.isSubtypeOf( + candidateReceiverType.prepared(), + expectedReceiverTypeClosestBound.prepared() + ) + } ?: run { + this.diagnosticsFromResolutionParts.add(NoContextReceiver(receiver)) + return null + } + result.add(selectedCandidate) + } + return result.map { ReceiverExpressionKotlinCallArgument(it) } + } } internal object CheckArgumentsInParenthesis : ResolutionPart() { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt index aba89485e18..592743aa5e7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.model import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate @@ -272,6 +273,12 @@ class CompatibilityWarningOnArgument( } } +class NoContextReceiver(val receiverDescriptor: ReceiverParameterDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) { + override fun report(reporter: DiagnosticReporter) { + reporter.onCall(this) + } +} + class KotlinConstraintSystemDiagnostic( val error: ConstraintSystemError ) : KotlinCallDiagnostic(error.applicability) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt index 60a478675e2..24d1801a827 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt @@ -76,6 +76,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() { abstract val explicitReceiverKind: ExplicitReceiverKind abstract val dispatchReceiverArgument: SimpleKotlinCallArgument? abstract val extensionReceiverArgument: SimpleKotlinCallArgument? + abstract var contextReceiversArguments: List abstract val typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping abstract val argumentMappingByOriginal: Map abstract val freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt index 4cc4cdbb9ab..b88d5b5b7be 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallAtoms.kt @@ -85,6 +85,7 @@ open class MutableResolvedCallAtom( open val reflectionCandidateType: UnwrappedType? = null, open val candidate: CallableReferenceResolutionCandidate? = null ) : ResolvedCallAtom() { + override var contextReceiversArguments: List = listOf() override lateinit var typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping override lateinit var argumentMappingByOriginal: Map override lateinit var freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.fir.kt new file mode 100644 index 00000000000..b899fb6fabc --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.fir.kt @@ -0,0 +1,20 @@ +class View + +context(View) val Int.dp get() = 42 * this + +fun View.f() { + 123.dp + with(123) { + dp + } +} + +fun Int.g(v: View) { + with(v) { + dp + } +} + +fun h() { + 123.dp +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt new file mode 100644 index 00000000000..12459b03d00 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt @@ -0,0 +1,20 @@ +class View + +context(View) val Int.dp get() = 42 * this + +fun View.f() { + 123.dp + with(123) { + dp + } +} + +fun Int.g(v: View) { + with(v) { + dp + } +} + +fun h() { + 123.dp +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.txt new file mode 100644 index 00000000000..30bb109131a --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.txt @@ -0,0 +1,13 @@ +package + +public val kotlin.Int.dp: kotlin.Int +public fun h(): kotlin.Unit +public fun View.f(): kotlin.Unit +public fun kotlin.Int.g(/*0*/ v: View): kotlin.Unit + +public final class View { + public constructor View() + 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/extensions/contextReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.fir.kt similarity index 100% rename from compiler/testData/diagnostics/tests/extensions/contextReceiver.fir.kt rename to compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.fir.kt diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceiver.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.kt similarity index 100% rename from compiler/testData/diagnostics/tests/extensions/contextReceiver.kt rename to compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.kt diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceiver.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.txt similarity index 100% rename from compiler/testData/diagnostics/tests/extensions/contextReceiver.txt rename to compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.txt diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.fir.kt new file mode 100644 index 00000000000..07456efbb33 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.fir.kt @@ -0,0 +1,48 @@ +interface Lazy + +context(Lazy, Lazy) +fun test1() {} + +context(Lazy) +fun Lazy.test2() {} + +context(Lazy>) +fun Lazy.test3() {} + +fun f(lazy1: Lazy, lazy2: Lazy, lazyT: Lazy, lazyLazyT: Lazy>) { + with(lazy1) { + with(lazy2) { + test1() + test2() + test3() + } + } + with(lazy2) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazyT) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazyLazyT) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazy1) { + with(lazyLazyT) { + test1() + test2() + test3() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt new file mode 100644 index 00000000000..8e4746a171a --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt @@ -0,0 +1,48 @@ +interface Lazy + +context(Lazy, Lazy) +fun test1() {} + +context(Lazy) +fun Lazy.test2() {} + +context(Lazy>) +fun Lazy.test3() {} + +fun f(lazy1: Lazy, lazy2: Lazy, lazyT: Lazy, lazyLazyT: Lazy>) { + with(lazy1) { + with(lazy2) { + test1() + test2() + test3() + } + } + with(lazy2) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazyT) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazyLazyT) { + with(lazy1) { + test1() + test2() + test3() + } + } + with(lazy1) { + with(lazyLazyT) { + test1() + test2() + test3() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.txt new file mode 100644 index 00000000000..19e33b75be5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.txt @@ -0,0 +1,12 @@ +package + +public fun f(/*0*/ lazy1: Lazy, /*1*/ lazy2: Lazy, /*2*/ lazyT: Lazy, /*3*/ lazyLazyT: Lazy>): kotlin.Unit +public fun test1(): kotlin.Unit +public fun Lazy.test2(): kotlin.Unit +public fun Lazy.test3(): kotlin.Unit + +public interface Lazy { + 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/extensions/contextReceivers/manyReceivers.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.fir.kt new file mode 100644 index 00000000000..fafd3248e0f --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.fir.kt @@ -0,0 +1,35 @@ +class A { + val a = 1 +} + +class B { + val b = 2 +} + +class C { + val c = 3 +} + +context(A, B) fun C.f() {} + +fun main(a: A, b: B, c: C) { + with(a) { + with(b) { + with(c) { + f() + } + } + } + with(b) { + with(c) { + with(a) { + f() + } + } + } + with(a) { + with(c) { + f() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt new file mode 100644 index 00000000000..9381c2a7945 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt @@ -0,0 +1,35 @@ +class A { + val a = 1 +} + +class B { + val b = 2 +} + +class C { + val c = 3 +} + +context(A, B) fun C.f() {} + +fun main(a: A, b: B, c: C) { + with(a) { + with(b) { + with(c) { + f() + } + } + } + with(b) { + with(c) { + with(a) { + f() + } + } + } + with(a) { + with(c) { + f() + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.txt new file mode 100644 index 00000000000..cae4526e3d9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.txt @@ -0,0 +1,28 @@ +package + +public fun main(/*0*/ a: A, /*1*/ b: B, /*2*/ c: C): kotlin.Unit +public fun C.f(): kotlin.Unit + +public final class A { + public constructor A() + public final val a: kotlin.Int = 1 + 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 B { + public constructor B() + public final val b: kotlin.Int = 2 + 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 C { + public constructor C() + public final val c: kotlin.Int = 3 + 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/extensions/contextReceivers/noExplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.fir.kt new file mode 100644 index 00000000000..6185382af14 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.fir.kt @@ -0,0 +1,18 @@ +class A +class B +class C + +context(A) fun B.f() {} +context(A) fun B.g() { + f() +} +context(A) fun C.h() { + f() +} + +fun A.q(b: B) { + with(b) { + f() + } + f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt new file mode 100644 index 00000000000..096fe15eb96 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt @@ -0,0 +1,18 @@ +class A +class B +class C + +context(A) fun B.f() {} +context(A) fun B.g() { + f() +} +context(A) fun C.h() { + f() +} + +fun A.q(b: B) { + with(b) { + f() + } + f() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.txt new file mode 100644 index 00000000000..c989406b311 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.txt @@ -0,0 +1,27 @@ +package + +public fun B.f(): kotlin.Unit +public fun B.g(): kotlin.Unit +public fun C.h(): kotlin.Unit +public fun A.q(/*0*/ b: B): kotlin.Unit + +public final class A { + public constructor 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 final class B { + public constructor B() + 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 C { + public constructor C() + 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/extensions/contextReceivers/plusMatrix.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt new file mode 100644 index 00000000000..a477e99e434 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt @@ -0,0 +1,15 @@ +// FIR_IDENTICAL +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface NumberOperations { + fun Number.plus(other: Number): Number +} + +class Matrix + +context(NumberOperations) fun Matrix.plus(other: Matrix): Matrix = TODO() + +fun NumberOperations.plusMatrix(m1: Matrix, m2: Matrix) { + m1.plus(m2) + m2.plus(m1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.txt new file mode 100644 index 00000000000..4503a9541ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.txt @@ -0,0 +1,18 @@ +package + +public fun Matrix.plus(/*0*/ other: Matrix): Matrix +public fun NumberOperations.plusMatrix(/*0*/ m1: Matrix, /*1*/ m2: Matrix): kotlin.Unit + +public final class Matrix { + public constructor Matrix() + 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 NumberOperations { + 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 fun kotlin.Number.plus(/*0*/ other: kotlin.Number): kotlin.Number +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.fir.kt new file mode 100644 index 00000000000..56b7826bcea --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.fir.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +class B(val x: X) + +context(T) +fun T.f(t: B) {} + +fun Int.main(a: A, b: B) { + a.f(b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt new file mode 100644 index 00000000000..430bbbf4e44 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class A +class B(val x: X) + +context(T) +fun T.f(t: B) {} + +fun Int.main(a: A, b: B) { + a.f(b) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.txt new file mode 100644 index 00000000000..2853b3591eb --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.txt @@ -0,0 +1,19 @@ +package + +public fun T.f(/*0*/ t: B): kotlin.Unit +public fun kotlin.Int.main(/*0*/ a: A, /*1*/ b: B): kotlin.Unit + +public final class A { + public constructor 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 final class B { + public constructor B(/*0*/ x: X) + public final val x: X + 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/extensions/contextReceivers/typeParameterizedList.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt new file mode 100644 index 00000000000..d66b071e38b --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.fir.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun listOf(vararg e: T): List = null!! + +class A + +context(List) +fun A.f() {} + +fun main() { + with(listOf(1, 2, 3)) { + A().f() + } + with(listOf("1", "2", "3")) { + A().f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt new file mode 100644 index 00000000000..313dd69f718 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt @@ -0,0 +1,17 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun listOf(vararg e: T): List = null!! + +class A + +context(List) +fun A.f() {} + +fun main() { + with(listOf(1, 2, 3)) { + A().f() + } + with(listOf("1", "2", "3")) { + A().f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.txt new file mode 100644 index 00000000000..aa8cfd66d1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.txt @@ -0,0 +1,12 @@ +package + +public fun listOf(/*0*/ vararg e: T /*kotlin.Array*/): kotlin.collections.List +public fun main(): kotlin.Unit +public fun A.f(): kotlin.Unit + +public final class A { + public constructor 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 +} diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt new file mode 100644 index 00000000000..3f80e0896af --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.fir.kt @@ -0,0 +1,18 @@ +open class A +class B +class C: A() + +context(A) +fun B.f() {} + +fun main() { + val b = B() + + b.f() + with(A()) { + b.f() + } + with(C()) { + b.f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt new file mode 100644 index 00000000000..52e77f6e02a --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt @@ -0,0 +1,18 @@ +open class A +class B +class C: A() + +context(A) +fun B.f() {} + +fun main() { + val b = B() + + b.f() + with(A()) { + b.f() + } + with(C()) { + b.f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.txt new file mode 100644 index 00000000000..5233804ec65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.txt @@ -0,0 +1,25 @@ +package + +public fun main(): kotlin.Unit +public fun B.f(): kotlin.Unit + +public open class A { + public constructor 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 final class B { + public constructor B() + 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 C : A { + public constructor C() + 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/extensions/contextReceivers/withExplicitReceiverError.fir.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt new file mode 100644 index 00000000000..49ed65412e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.fir.kt @@ -0,0 +1,18 @@ +class A +class B +class C + +context(A) +fun B.f() {} + +fun main() { + val b = B() + + b.f() + with(A()) { + b.f() + } + with(C()) { + b.f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt new file mode 100644 index 00000000000..f2316d19c09 --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt @@ -0,0 +1,18 @@ +class A +class B +class C + +context(A) +fun B.f() {} + +fun main() { + val b = B() + + b.f() + with(A()) { + b.f() + } + with(C()) { + b.f() + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.txt b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.txt new file mode 100644 index 00000000000..5c7ae405e8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.txt @@ -0,0 +1,25 @@ +package + +public fun main(): kotlin.Unit +public fun B.f(): kotlin.Unit + +public final class A { + public constructor 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 final class B { + public constructor B() + 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 C { + public constructor C() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-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 ef4200705cd..559129a82a8 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 @@ -10477,12 +10477,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/extensions/classObject.kt"); } - @Test - @TestMetadata("contextReceiver.kt") - public void testContextReceiver() throws Exception { - runTest("compiler/testData/diagnostics/tests/extensions/contextReceiver.kt"); - } - @Test @TestMetadata("ExtensionFunctions.kt") public void testExtensionFunctions() throws Exception { @@ -10578,6 +10572,76 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testVariableInvoke() throws Exception { runTest("compiler/testData/diagnostics/tests/extensions/variableInvoke.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/extensions/contextReceivers") + @TestDataPath("$PROJECT_ROOT") + public class ContextReceivers { + @Test + public void testAllFilesPresentInContextReceivers() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/extensions/contextReceivers"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("dp.kt") + public void testDp() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/dp.kt"); + } + + @Test + @TestMetadata("insideDeclaration.kt") + public void testInsideDeclaration() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/insideDeclaration.kt"); + } + + @Test + @TestMetadata("lazy.kt") + public void testLazy() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/lazy.kt"); + } + + @Test + @TestMetadata("manyReceivers.kt") + public void testManyReceivers() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/manyReceivers.kt"); + } + + @Test + @TestMetadata("noExplicitReceiver.kt") + public void testNoExplicitReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/noExplicitReceiver.kt"); + } + + @Test + @TestMetadata("plusMatrix.kt") + public void testPlusMatrix() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/plusMatrix.kt"); + } + + @Test + @TestMetadata("typeParameterized.kt") + public void testTypeParameterized() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterized.kt"); + } + + @Test + @TestMetadata("typeParameterizedList.kt") + public void testTypeParameterizedList() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/typeParameterizedList.kt"); + } + + @Test + @TestMetadata("withExplicitReceiver.kt") + public void testWithExplicitReceiver() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiver.kt"); + } + + @Test + @TestMetadata("withExplicitReceiverError.kt") + public void testWithExplicitReceiverError() throws Exception { + runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/withExplicitReceiverError.kt"); + } + } } @Nested diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 494b098f70c..a6972d3512c 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -84,6 +84,8 @@ fun KotlinType.isPrimitiveNumberOrNullableType(): Boolean = fun KotlinType.isTypeParameter(): Boolean = TypeUtils.isTypeParameter(this) +fun KotlinType.containsTypeParameter(): Boolean = TypeUtils.contains(this) { t -> TypeUtils.isTypeParameter(t) } + fun KotlinType.upperBoundedByPrimitiveNumberOrNullableType(): Boolean = TypeUtils.getTypeParameterDescriptorOrNull(this)?.upperBounds?.any { it.isPrimitiveNumberOrNullableType() || it.upperBoundedByPrimitiveNumberOrNullableType() diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt index fdfb00afe74..7ddfa613775 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/utils.kt @@ -233,6 +233,7 @@ private fun resolveAccessorCall( override fun getResultingDescriptor() = suspendPropertyDescriptor override fun getExtensionReceiver() = null override fun getDispatchReceiver() = null + override fun getContextReceivers(): List = emptyList() override fun getExplicitReceiverKind() = ExplicitReceiverKind.NO_EXPLICIT_RECEIVER override fun getValueArguments(): MutableMap = mutableMapOf() override fun getValueArgumentsByIndex(): MutableList = mutableListOf()