diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index 94e35d12994..b495012c3b5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -438,7 +438,7 @@ internal object CheckVisibility : CheckerStage() { canSeePrivateMemberOf(containingDeclarations, ownerId, session) } } else { - false + declaration is FirSimpleFunction && declaration.isAllowedToBeAccessedFromOutside() } } Visibilities.PROTECTED -> { @@ -461,6 +461,16 @@ internal object CheckVisibility : CheckerStage() { return true } + // monitorEnter/monitorExit are the only functions which are accessed "illegally" (see kotlin/util/Synchronized.kt). + // Since they are intrinsified in the codegen, FIR should treat it as visible. + private fun FirSimpleFunction.isAllowedToBeAccessedFromOutside(): Boolean { + if (!isFromLibrary) return false + val packageName = symbol.callableId.packageName.asString() + val name = name.asString() + return packageName == "kotlin.jvm.internal.unsafe" && + (name == "monitorEnter" || name == "monitorExit") + } + private fun AbstractFirBasedSymbol<*>.getOwnerId(): ClassId? { return when (this) { is FirClassLikeSymbol<*> -> { diff --git a/compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt b/compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt index 2481400aafd..c157415377c 100644 --- a/compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt +++ b/compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME import kotlin.jvm.internal.unsafe.*