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:
Alexey Andreev
2016-12-14 14:07:10 +03:00
parent 87f4e53544
commit c82f8213b0
8 changed files with 41 additions and 13 deletions
@@ -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
@@ -1,5 +1,3 @@
// TARGET_BACKEND: JVM
open class Father(val param: String) {
abstract inner class InClass {
fun work(): String {
@@ -1,5 +1,3 @@
// TARGET_BACKEND: JVM
class A {
open inner class Inner(val result: String)
@@ -1,5 +1,3 @@
// TARGET_BACKEND: JVM
class A {
open inner class Inner(val result: String = "OK", val int: Int)
@@ -1,5 +1,3 @@
// TARGET_BACKEND: JVM
fun box(): String {
val capture = "oh"
@@ -1,5 +1,3 @@
// TARGET_BACKEND: JVM
fun box(): String {
class Local {
open inner class Inner(val s: String) {
@@ -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");
@@ -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)) {