JS: fix translation of callable reference to property of outer class with private setter
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
|||||||
|
class A {
|
||||||
|
var value: String = "fail1"
|
||||||
|
private set
|
||||||
|
|
||||||
|
inner class B {
|
||||||
|
fun foo(): kotlin.reflect.KMutableProperty0<String> = this@A::value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
var value: String = "fail2"
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun bar(): kotlin.reflect.KMutableProperty0<String> {
|
||||||
|
class D {
|
||||||
|
fun foo(): kotlin.reflect.KMutableProperty0<String> = this@C::value
|
||||||
|
}
|
||||||
|
|
||||||
|
return D().foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A()
|
||||||
|
a.B().foo().set("O")
|
||||||
|
|
||||||
|
val c = C()
|
||||||
|
c.bar().set("K")
|
||||||
|
|
||||||
|
return a.value + c.value
|
||||||
|
}
|
||||||
Vendored
+30
@@ -0,0 +1,30 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
public final class A {
|
||||||
|
private @org.jetbrains.annotations.NotNull field value: java.lang.String
|
||||||
|
inner class A/B
|
||||||
|
public method <init>(): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method getValue(): java.lang.String
|
||||||
|
private final method setValue(p0: java.lang.String): void
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class A/B {
|
||||||
|
synthetic final field this$0: A
|
||||||
|
inner class A/B
|
||||||
|
public method <init>(p0: A): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method foo(): kotlin.reflect.KMutableProperty0
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class C {
|
||||||
|
private @org.jetbrains.annotations.NotNull field value: java.lang.String
|
||||||
|
public method <init>(): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method bar(): kotlin.reflect.KMutableProperty0
|
||||||
|
public final @org.jetbrains.annotations.NotNull method getValue(): java.lang.String
|
||||||
|
private final method setValue(p0: java.lang.String): void
|
||||||
|
}
|
||||||
|
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class PrivateSetOuterClassKt {
|
||||||
|
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||||
|
}
|
||||||
+6
@@ -2176,6 +2176,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateSetOuterClass.kt")
|
||||||
|
public void testPrivateSetOuterClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateSetterInsideClass.kt")
|
@TestMetadata("privateSetterInsideClass.kt")
|
||||||
public void testPrivateSetterInsideClass() throws Exception {
|
public void testPrivateSetterInsideClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
||||||
|
|||||||
@@ -2176,6 +2176,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateSetOuterClass.kt")
|
||||||
|
public void testPrivateSetOuterClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateSetterInsideClass.kt")
|
@TestMetadata("privateSetterInsideClass.kt")
|
||||||
public void testPrivateSetterInsideClass() throws Exception {
|
public void testPrivateSetterInsideClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
||||||
|
|||||||
@@ -2176,6 +2176,12 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateSetOuterClass.kt")
|
||||||
|
public void testPrivateSetOuterClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateSetterInsideClass.kt")
|
@TestMetadata("privateSetterInsideClass.kt")
|
||||||
public void testPrivateSetterInsideClass() throws Exception {
|
public void testPrivateSetterInsideClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
||||||
|
|||||||
@@ -2561,6 +2561,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateSetOuterClass.kt")
|
||||||
|
public void testPrivateSetOuterClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateSetterInsideClass.kt")
|
@TestMetadata("privateSetterInsideClass.kt")
|
||||||
public void testPrivateSetterInsideClass() throws Exception {
|
public void testPrivateSetterInsideClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/property/privateSetterInsideClass.kt");
|
||||||
|
|||||||
+4
-1
@@ -142,7 +142,10 @@ object CallableReferenceTranslator {
|
|||||||
val setter = descriptor.setter ?: return false
|
val setter = descriptor.setter ?: return false
|
||||||
if (setter.visibility != Visibilities.PRIVATE) return true
|
if (setter.visibility != Visibilities.PRIVATE) return true
|
||||||
val classDescriptor = context.classDescriptor ?: return false
|
val classDescriptor = context.classDescriptor ?: return false
|
||||||
return classDescriptor == descriptor.containingDeclaration
|
|
||||||
|
val outerClasses = generateSequence<DeclarationDescriptor>(classDescriptor) { it.containingDeclaration }
|
||||||
|
.filterIsInstance<ClassDescriptor>()
|
||||||
|
return descriptor.containingDeclaration in outerClasses
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun translateForPropertyAccessor(
|
private fun translateForPropertyAccessor(
|
||||||
|
|||||||
Reference in New Issue
Block a user