KT-11960 Fix case of instantiation of local class via its inner class or via nested lambda. Move tests to more appropriate location. Fix bug in blackbox codegen generator for JVM, which does not allow to suppress tests.

This commit is contained in:
Alexey Andreev
2016-05-23 12:17:56 +03:00
parent bb8a3aa262
commit acc5303731
9 changed files with 56 additions and 45 deletions
@@ -47,6 +47,12 @@ public class LocalClassesTestGenerated extends AbstractLocalClassesTest {
doTest(fileName);
}
@TestMetadata("closureWithSelfInstantiation.kt")
public void testClosureWithSelfInstantiation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/closureWithSelfInstantiation.kt");
doTest(fileName);
}
@TestMetadata("inExtensionFunction.kt")
public void testInExtensionFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/inExtensionFunction.kt");
@@ -143,6 +149,12 @@ public class LocalClassesTestGenerated extends AbstractLocalClassesTest {
doTest(fileName);
}
@TestMetadata("localDataClass.kt")
public void testLocalDataClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/localDataClass.kt");
doTest(fileName);
}
@TestMetadata("localExtendsInnerAndReferencesOuterMember.kt")
public void testLocalExtendsInnerAndReferencesOuterMember() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/localClasses/localExtendsInnerAndReferencesOuterMember.kt");
@@ -161,18 +161,6 @@ public class SecondaryConstructorTestGenerated extends AbstractSecondaryConstruc
doTest(fileName);
}
@TestMetadata("localClassesWithSelfInstantiation.kt")
public void testLocalClassesWithSelfInstantiation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/localClassesWithSelfInstantiation.kt");
doTest(fileName);
}
@TestMetadata("localDataClass.kt")
public void testLocalDataClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/localDataClass.kt");
doTest(fileName);
}
@TestMetadata("superCallPrimary.kt")
public void testSuperCallPrimary() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/superCallPrimary.kt");
@@ -35,4 +35,8 @@ package org.jetbrains.kotlin.js.translate.context
import com.google.dart.compiler.backend.js.ast.JsExpression
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
class DeferredCallSite(val constructor: ConstructorDescriptor, val invocationArgs: MutableList<JsExpression>)
class DeferredCallSite(
val constructor: ConstructorDescriptor,
val invocationArgs: MutableList<JsExpression>,
val context: TranslationContext
)
@@ -537,6 +537,6 @@ public class TranslationContext {
List<DeferredCallSite> callSites = staticContext.getDeferredCallSites().get(classDescriptor);
if (callSites == null) throw new IllegalStateException("This method should be call only when `shouldBeDeferred` method " +
"reports true for given constructor: " + constructor);
callSites.add(new DeferredCallSite(constructor, invocationArgs));
callSites.add(new DeferredCallSite(constructor, invocationArgs, this));
}
}
@@ -276,15 +276,19 @@ class ClassTranslator private constructor(
val capturedVars = (nonConstructorCapturedVars + constructorCapturedVars).distinct()
val descriptor = constructor.descriptor
val classDescriptor = DescriptorUtils.getParentOfType(descriptor, ClassDescriptor::class.java, false)!!
nonConstructorContext.putClassOrConstructorClosure(descriptor, capturedVars)
val constructorCallSites = callSiteMap[constructor.descriptor].orEmpty()
for (callSite in constructorCallSites) {
val closureQualifier = callSite.context.getArgumentForClosureConstructor(classDescriptor.thisAsReceiverParameter)
capturedVars.forEach { nonConstructorUsageTracker.used(it) }
val closureArgs = capturedVars
.map { nonConstructorUsageTracker.capturedDescriptorToJsName[it]!! }
.map { JsAstUtils.fqnWithoutSideEffects(it, JsLiteral.THIS) }
callSite.invocationArgs.addAll(0, closureArgs)
val closureArgs = capturedVars.map {
val name = nonConstructorUsageTracker.getNameForCapturedDescriptor(it)!!
JsAstUtils.fqnWithoutSideEffects(name, closureQualifier)
}
callSite.invocationArgs.addAll(0, closureArgs.toList())
}
}
}