[FIR] Make lambda parameters of dynamic function calls dynamic
#KT-57961 Fixed
This commit is contained in:
committed by
Space Team
parent
a3bf61c3f7
commit
ff7072830f
+8
-3
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.inference
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnonymousFunctionExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ArgumentTypeMismatch
|
||||
@@ -119,13 +120,17 @@ private fun extractLambdaInfo(
|
||||
argument.returnType
|
||||
?: typeVariable.defaultType
|
||||
|
||||
val nothingType = session.builtinTypes.nothingType.type
|
||||
val defaultType = when (candidate?.symbol?.origin) {
|
||||
FirDeclarationOrigin.DynamicScope -> ConeDynamicType.create(session)
|
||||
else -> session.builtinTypes.nothingType.type
|
||||
}
|
||||
|
||||
val parameters = argument.valueParameters.map {
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: nothingType
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: defaultType
|
||||
}
|
||||
|
||||
val contextReceivers = argument.contextReceivers.map {
|
||||
it.typeRef.coneTypeSafe<ConeKotlinType>() ?: nothingType
|
||||
it.typeRef.coneTypeSafe<ConeKotlinType>() ?: defaultType
|
||||
}
|
||||
|
||||
val newTypeVariableUsed = returnType == typeVariable.defaultType
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
fun box(): String {
|
||||
val foo = js("{ bar: function(x, y) { return y(x) } }")
|
||||
val bar = js("{ baz: 'OK' }")
|
||||
return foo.bar(bar) { x -> x.baz }
|
||||
}
|
||||
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
public final fun foo(/*0*/ p0: () -> dynamic): dynamic
|
||||
public final fun foo(/*0*/ p0: () -> dynamic): dynamic
|
||||
public final fun foo(/*0*/ p0: (dynamic) -> dynamic): dynamic
|
||||
public final fun bar(): dynamic
|
||||
public final fun foo(/*0*/ p0: (dynamic) -> dynamic): dynamic
|
||||
public final fun foo(/*0*/ p0: (dynamic, dynamic) -> dynamic): dynamic
|
||||
public final fun foo(/*0*/ p0: (dynamic, dynamic) -> dynamic): dynamic
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ fun test(d: dynamic) {
|
||||
|
||||
d.foo { <!UNRESOLVED_REFERENCE!>it<!> }
|
||||
|
||||
d.foo { x -> }
|
||||
d.foo { x -> x.bar() }
|
||||
|
||||
d.foo { x: Int -> "" }
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ fun test(d: dynamic) {
|
||||
|
||||
d.foo { <!UNRESOLVED_REFERENCE!>it<!> }
|
||||
|
||||
d.foo { x -> }
|
||||
d.foo { x -> x.bar() }
|
||||
|
||||
d.foo { x: Int -> "" }
|
||||
|
||||
|
||||
+6
@@ -21664,6 +21664,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("trailingLambdaOnDynamic.kt")
|
||||
public void testTrailingLambdaOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21802,6 +21802,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("trailingLambdaOnDynamic.kt")
|
||||
public void testTrailingLambdaOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21802,6 +21802,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("trailingLambdaOnDynamic.kt")
|
||||
public void testTrailingLambdaOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21802,6 +21802,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("trailingLambdaOnDynamic.kt")
|
||||
public void testTrailingLambdaOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user