JS: Fix capturing class construction function for lambdas inside inline functions with reified type parameters (KT-13522).
This commit is contained in:
@@ -6464,6 +6464,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jsClassOnReifiedTypeInLambda.kt")
|
||||||
|
public void testJsClassOnReifiedTypeInLambda() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/jsClassOnReifiedTypeInLambda.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("jsClassSimpleName.kt")
|
@TestMetadata("jsClassSimpleName.kt")
|
||||||
public void testJsClassSimpleName() throws Exception {
|
public void testJsClassSimpleName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/jsClassSimpleName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/jsClassSimpleName.kt");
|
||||||
@@ -6488,6 +6494,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kClassOnReifiedTypeInLambda.kt")
|
||||||
|
public void testKClassOnReifiedTypeInLambda() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/kClassOnReifiedTypeInLambda.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kClassSimpleName.kt")
|
@TestMetadata("kClassSimpleName.kt")
|
||||||
public void testKClassSimpleName() throws Exception {
|
public void testKClassSimpleName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/reflection/kClassSimpleName.kt");
|
||||||
|
|||||||
+6
@@ -141,6 +141,12 @@ fun JsFunction.withCapturedParameters(
|
|||||||
var additionalArgs = listOf(capturedRef)
|
var additionalArgs = listOf(capturedRef)
|
||||||
var additionalParams = listOf(JsParameter(name))
|
var additionalParams = listOf(JsParameter(name))
|
||||||
|
|
||||||
|
if (capturedDescriptor is TypeParameterDescriptor && capturedDescriptor.isReified) {
|
||||||
|
// Preserve the usual order
|
||||||
|
additionalArgs = listOf(invokingContext.getNameForDescriptor(capturedDescriptor).makeRef()) + additionalArgs
|
||||||
|
additionalParams = listOf(JsParameter(context.getNameForDescriptor(capturedDescriptor))) + additionalParams
|
||||||
|
}
|
||||||
|
|
||||||
if (capturedDescriptor is CallableDescriptor && isLocalInlineDeclaration(capturedDescriptor)) {
|
if (capturedDescriptor is CallableDescriptor && isLocalInlineDeclaration(capturedDescriptor)) {
|
||||||
val aliasRef = capturedRef as? JsNameRef
|
val aliasRef = capturedRef as? JsNameRef
|
||||||
val localFunAlias = aliasRef?.getStaticRef() as? JsExpression
|
val localFunAlias = aliasRef?.getStaticRef() as? JsExpression
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ fun getReferenceToJsClass(type: KotlinType, context: TranslationContext): JsExpr
|
|||||||
is TypeParameterDescriptor -> {
|
is TypeParameterDescriptor -> {
|
||||||
assert(classifierDescriptor.isReified)
|
assert(classifierDescriptor.isReified)
|
||||||
|
|
||||||
|
context.usageTracker()?.used(classifierDescriptor)
|
||||||
|
|
||||||
context.getNameForDescriptor(classifierDescriptor).makeRef()
|
context.getNameForDescriptor(classifierDescriptor).makeRef()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
inline fun <reified T : Any> foo(): () -> JsClass<T> {
|
||||||
|
val T = 1
|
||||||
|
return { jsClass<T>() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
check(jsClass<A>(), foo<A>()())
|
||||||
|
check(jsClass<B>(), foo<B>()())
|
||||||
|
check(jsClass<O>(), foo<O>()())
|
||||||
|
check(jsClass<E>(), foo<E>()())
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
inline fun <reified T : Any> foo(b: Boolean = false): () -> KClass<T> {
|
||||||
|
if (b) {
|
||||||
|
val T = 1
|
||||||
|
}
|
||||||
|
return { T::class }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
check(A::class, foo<A>()())
|
||||||
|
check(B::class, foo<B>()())
|
||||||
|
check(O::class, foo<O>()())
|
||||||
|
check(E::class, foo<E>()())
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user