Skip to content

Commit 46af453

Browse files
committed
JVM KT-49613 don't generate indy reference to protected constructor
1 parent a3820d4 commit 46af453

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
lines changed

compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil
270270
targetRef: IrFunctionReference
271271
): IrCall {
272272
fun fail(message: String): Nothing =
273-
throw AssertionError("$message, irFunRef:\n${targetRef.dump()}")
273+
throw AssertionError("$message, targetRef:\n${targetRef.dump()}")
274274

275275
val dynamicCallArguments = ArrayList<IrExpression>()
276276

compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ internal class LambdaMetafactoryArgumentsBuilder(
9191
if (implFun.isInline)
9292
return null
9393

94-
if (implFun is IrConstructor && DescriptorVisibilities.isPrivate(implFun.visibility)) {
94+
if (isConstructorRequiringAccessor(implFun)) {
9595
// Kotlin generates constructor accessors differently from Java.
96-
// TODO more precise accessibility check (see SyntheticAccessorLowering::isAccessible)
9796
return null
9897
}
9998

@@ -138,6 +137,15 @@ internal class LambdaMetafactoryArgumentsBuilder(
138137
return getLambdaMetafactoryArgsOrNullInner(reference, samMethod, samType, implFun)
139138
}
140139

140+
private fun isConstructorRequiringAccessor(implFun: IrFunction): Boolean {
141+
if (implFun !is IrConstructor) return false
142+
// We don't do exact accessibility check here:
143+
// constructor will be called by a class generated by LambdaMetafactory at runtime.
144+
val visibility = implFun.visibility
145+
return visibility == DescriptorVisibilities.PROTECTED ||
146+
DescriptorVisibilities.isPrivate(visibility)
147+
}
148+
141149
private val javaIoSerializableFqn =
142150
FqName("java.io").child(Name.identifier("Serializable"))
143151

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// TARGET_BACKEND: JVM
2+
// JVM_TARGET: 1.8
3+
// SAM_CONVERSIONS: INDY
4+
// FILE: kt49613.kt
5+
6+
interface GetStep {
7+
fun get(): Any
8+
}
9+
10+
class Outer protected constructor(val ok: Any) {
11+
constructor(): this("xxx")
12+
13+
val obj = object : GetStep {
14+
override fun get() = Step(::Outer)
15+
}
16+
}
17+
18+
fun box(): String {
19+
val s = Outer().obj.get() as Step
20+
val t = s.step("OK") as Outer
21+
return t.ok as String
22+
}
23+
24+
// FILE: Step.java
25+
26+
public interface Step {
27+
Object step(String string);
28+
}

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)