diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index 7d508a34a0c..f317b4be27f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -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() ?: nothingType + it.returnTypeRef.coneTypeSafe() ?: defaultType } val contextReceivers = argument.contextReceivers.map { - it.typeRef.coneTypeSafe() ?: nothingType + it.typeRef.coneTypeSafe() ?: defaultType } val newTypeVariableUsed = returnType == typeVariable.defaultType diff --git a/compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt b/compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt new file mode 100644 index 00000000000..6662952cdb9 --- /dev/null +++ b/compiler/testData/codegen/box/js/trailingLambdaOnDynamic.kt @@ -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 } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.dynamic.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.dynamic.txt index 9cb618d1b4b..313641deed5 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.dynamic.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.dynamic.txt @@ -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 diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt index 3170ff580ba..2bc4ec9e032 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.fir.kt @@ -6,7 +6,7 @@ fun test(d: dynamic) { d.foo { it } - d.foo { x -> } + d.foo { x -> x.bar() } d.foo { x: Int -> "" } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt index 85c458d796e..8c814e34414 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt @@ -6,7 +6,7 @@ fun test(d: dynamic) { d.foo { it } - d.foo { x -> } + d.foo { x -> x.bar() } d.foo { x: Int -> "" } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index ba5c9c997e1..646570a917d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -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 diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 88eedd5e537..618fe5d9b85 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -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 diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 2f14e177fc0..390b4358355 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -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 diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index c5784564f4d..32a7b80ba61 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -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