JS: extract outer class reference as dispatchReceiver from ResolvedCall, to include it into UsageTracker mechanism. This allows to capture outer class of super class in local classes. See KT-13166
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// See KT-9246 IllegalAccessError when trying to access protected nested class from parent class
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: a.kt
|
||||
|
||||
package a
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
open class Father(val param: String) {
|
||||
abstract inner class InClass {
|
||||
fun work(): String {
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class A {
|
||||
open inner class Inner(val result: String)
|
||||
|
||||
|
||||
Vendored
-2
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class A {
|
||||
open inner class Inner(val result: String = "OK", val int: Int)
|
||||
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
fun box(): String {
|
||||
val capture = "oh"
|
||||
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
fun box(): String {
|
||||
class Local {
|
||||
open inner class Inner(val s: String) {
|
||||
|
||||
+36
@@ -9453,6 +9453,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("protectedNestedClass.kt")
|
||||
public void testProtectedNestedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/protectedNestedClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -9503,6 +9509,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localExtendsInner.kt")
|
||||
public void testLocalExtendsInner() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsInner.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localExtendsLocalWithClosure.kt")
|
||||
public void testLocalExtendsLocalWithClosure() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/localExtendsLocalWithClosure.kt");
|
||||
@@ -9527,6 +9539,30 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExtendsInner.kt")
|
||||
public void testObjectExtendsInner() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInner.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExtendsInnerDefaultArgument.kt")
|
||||
public void testObjectExtendsInnerDefaultArgument() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerDefaultArgument.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExtendsInnerOfLocalVarargAndDefault.kt")
|
||||
public void testObjectExtendsInnerOfLocalVarargAndDefault() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerOfLocalVarargAndDefault.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExtendsInnerOfLocalWithCapture.kt")
|
||||
public void testObjectExtendsInnerOfLocalWithCapture() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsInnerOfLocalWithCapture.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExtendsLocalCaptureInSuperCall.kt")
|
||||
public void testObjectExtendsLocalCaptureInSuperCall() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/innerNested/superConstructorCall/objectExtendsLocalCaptureInSuperCall.kt");
|
||||
|
||||
+5
-2
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.AstUtilsKt;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||
@@ -200,8 +201,10 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
if (superDescriptor.getConstructedClass().isInner() && classDescriptor.isInner()) {
|
||||
arguments.add(pureFqn(Namer.OUTER_FIELD_NAME, JsLiteral.THIS));
|
||||
if (superCall.getDispatchReceiver() != null) {
|
||||
JsExpression receiver = context.getDispatchReceiver(JsDescriptorUtils.getReceiverParameterForReceiver(
|
||||
superCall.getDispatchReceiver()));
|
||||
arguments.add(receiver);
|
||||
}
|
||||
|
||||
if (!DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
||||
|
||||
Reference in New Issue
Block a user