From d6091c93a11dae38b63e10ea986ce7aca3378255 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 21 Nov 2018 12:44:40 +0300 Subject: [PATCH] Inliner: fixed bug with generic function reference + test Fixes issue https://github.com/JetBrains/kotlin-native/issues/2336 --- .../backend/konan/lower/FunctionInlining.kt | 2 ++ backend.native/tests/build.gradle | 5 +++++ .../inline/genericFunctionReference.kt | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 backend.native/tests/codegen/inline/genericFunctionReference.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 3ece80d6d97..ecec92791f1 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -359,6 +359,8 @@ private class Inliner(val globalSubstituteMap: MutableMap are used" } + for (index in 0 until functionArgument.typeArgumentsCount) + putTypeArgument(index, functionArgument.getTypeArgument(index)) } return owner.visitCall(super.visitCall(immediateCall) as IrCall, Ref(false)) } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 844f22a67e2..8bf14f00800 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2586,6 +2586,11 @@ task inline_localObjectReturnedFromWhen(type: RunKonanTest) { source = "codegen/inline/localObjectReturnedFromWhen.kt" } +task inline_genericFunctionReference(type: RunKonanTest) { + goldValue = "0\n" + source = "codegen/inline/genericFunctionReference.kt" +} + task classDeclarationInsideInline(type: RunKonanTest) { source = "codegen/inline/classDeclarationInsideInline.kt" goldValue = "test1: 1.0\n1\ntest2\n" diff --git a/backend.native/tests/codegen/inline/genericFunctionReference.kt b/backend.native/tests/codegen/inline/genericFunctionReference.kt new file mode 100644 index 00000000000..70ec4e151b0 --- /dev/null +++ b/backend.native/tests/codegen/inline/genericFunctionReference.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package codegen.inline.genericFunctionReference + +import kotlin.test.* + +class Z(val x: T) + +inline fun foo(x: T, f: (T) -> R): R { + return f(x) +} + +@Test fun runTest() { + val arr = Array(1) { foo(it, ::Z) } + println(arr[0].x) +} \ No newline at end of file