From e0bcba5c0ee578d660926d13b3a0f14db8665b21 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 2 Jan 2019 11:39:28 +0100 Subject: [PATCH] Add test for obsolete KT-17431 issue #KT-17431 Obsolete --- .../codegen/boxInline/simple/kt17431.kt | 36 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 5 +++ ...otlinAgainstInlineKotlinTestGenerated.java | 5 +++ .../IrBlackBoxInlineCodegenTestGenerated.java | 5 +++ 4 files changed, 51 insertions(+) create mode 100644 compiler/testData/codegen/boxInline/simple/kt17431.kt diff --git a/compiler/testData/codegen/boxInline/simple/kt17431.kt b/compiler/testData/codegen/boxInline/simple/kt17431.kt new file mode 100644 index 00000000000..04bdbb4c131 --- /dev/null +++ b/compiler/testData/codegen/boxInline/simple/kt17431.kt @@ -0,0 +1,36 @@ +// WITH_RUNTIME +// FILE: 1.kt +package test + +class WeakReference(val value: T) + +inline fun MutableMap>.getOrPutWeak(key: K, defaultValue: ()->V): V { + val value = get(key)?.value + return if (value == null) { + val answer = defaultValue() + put(key, WeakReference(answer)) + answer + } else { + value + } +} + + +// FILE: 2.kt +import test.* + +class LabelHolder { + + fun test(): String { + return "hello".label + } + + private val labels = hashMapOf>() + + private val String?.label: String + get(): String = labels.getOrPutWeak(this) { "OK" } +} + +fun box(): String { + return LabelHolder().test() +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index c1f16a71a9e..bd9894ab702 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2808,6 +2808,11 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/simple/funImportedFromObject.kt"); } + @TestMetadata("kt17431.kt") + public void testKt17431() throws Exception { + runTest("compiler/testData/codegen/boxInline/simple/kt17431.kt"); + } + @TestMetadata("params.kt") public void testParams() throws Exception { runTest("compiler/testData/codegen/boxInline/simple/params.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 17628d6d0ac..bb3c12e23a3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2808,6 +2808,11 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/simple/funImportedFromObject.kt"); } + @TestMetadata("kt17431.kt") + public void testKt17431() throws Exception { + runTest("compiler/testData/codegen/boxInline/simple/kt17431.kt"); + } + @TestMetadata("params.kt") public void testParams() throws Exception { runTest("compiler/testData/codegen/boxInline/simple/params.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 59e4a56de2b..4f26856960b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -2808,6 +2808,11 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/simple/funImportedFromObject.kt"); } + @TestMetadata("kt17431.kt") + public void testKt17431() throws Exception { + runTest("compiler/testData/codegen/boxInline/simple/kt17431.kt"); + } + @TestMetadata("params.kt") public void testParams() throws Exception { runTest("compiler/testData/codegen/boxInline/simple/params.kt");