diff --git a/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.kt b/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.kt new file mode 100644 index 00000000000..b3f50a3904d --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.kt @@ -0,0 +1,24 @@ +import java.util.* +import java.util.function.BiConsumer + +private val DEBUG = true + +abstract class SomeHashTable : AbstractMutableMap() { + override fun forEach(action: BiConsumer) {} + + override val entries: MutableSet> + get() { + if (DEBUG) { + return Collections.unmodifiableSet( + mutableSetOf>().apply { + forEach { key, value -> add(Entry(key, value)) } + } + ) + } + throw UnsupportedOperationException() + } + + private class Entry(override val key: K, override val value: V) : MutableMap.MutableEntry { + override fun setValue(newValue: V): V = throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.txt b/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.txt new file mode 100644 index 00000000000..73121d103f0 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.txt @@ -0,0 +1,46 @@ +FILE: hashTableWithForEach.kt + private final val DEBUG: R|kotlin/Boolean| = Boolean(true) + private get(): R|kotlin/Boolean| + public abstract class SomeHashTable : R|kotlin/collections/AbstractMutableMap| { + public constructor(): R|SomeHashTable| { + super|>() + } + + public open override fun forEach(action: R|java/util/function/BiConsumer|): R|kotlin/Unit| { + } + + public open override val entries: R|kotlin/collections/MutableSet>| + public get(): R|kotlin/collections/MutableSet>| { + when () { + R|/DEBUG| -> { + ^ Q|java/util/Collections|.R|java/util/Collections.unmodifiableSet||>(R|kotlin/collections/mutableSetOf||>().R|kotlin/apply|>|>( = apply@fun R|kotlin/collections/MutableSet>|.(): R|kotlin/Unit| { + this@R|/SomeHashTable|.R|FakeOverride|( = forEach@fun (key: R|K!|, value: R|V!|): R|kotlin/Unit| { + this@R|kotlin/collections/MutableSet|.R|FakeOverride|(R|/SomeHashTable.Entry.Entry|(R|/key|, R|/value|)) + } + ) + } + )) + } + } + + throw R|java/lang/UnsupportedOperationException.UnsupportedOperationException|() + } + + private final class Entry : R|kotlin/collections/MutableMap.MutableEntry| { + public constructor(key: R|K|, value: R|V|): R|SomeHashTable.Entry| { + super() + } + + public final override val key: R|K| = R|/key| + public get(): R|K| + + public final override val value: R|V| = R|/value| + public get(): R|V| + + public final override fun setValue(newValue: R|V|): R|V| { + ^setValue throw R|java/lang/UnsupportedOperationException.UnsupportedOperationException|() + } + + } + + } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.kt b/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.kt new file mode 100644 index 00000000000..935302e8989 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.kt @@ -0,0 +1,15 @@ +import java.util.* + +interface ArgsInfo + +class ArgsInfoImpl : ArgsInfo { + constructor(info: ArgsInfo) {} +} + +typealias Arguments = Map + +fun Arguments.deepCopy(): Arguments { + val result = HashMap() + this.forEach { key, value -> result[key] = ArgsInfoImpl(value) } + return result +} diff --git a/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.txt b/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.txt new file mode 100644 index 00000000000..505a7674e41 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.txt @@ -0,0 +1,18 @@ +FILE: typeAliasWithForEach.kt + public abstract interface ArgsInfo : R|kotlin/Any| { + } + public final class ArgsInfoImpl : R|ArgsInfo| { + public constructor(info: R|ArgsInfo|): R|ArgsInfoImpl| { + super() + } + + } + public final typealias Arguments = R|kotlin/collections/Map| + public final fun R|Arguments|.deepCopy(): R|Arguments| { + lval result: R|java/util/HashMap| = R|java/util/HashMap.HashMap|() + this@R|/deepCopy|.R|FakeOverride|( = forEach@fun (key: R|kotlin/String!|, value: R|ArgsInfo!|): R|kotlin/Unit| { + R|/result|.R|kotlin/collections/set|(R|/key|, R|/ArgsInfoImpl.ArgsInfoImpl|(R|/value|)) + } + ) + ^deepCopy R|/result| + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 667b1f5ebd4..1409df9aaae 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -98,6 +98,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolve/stdlib/hashSet.kt"); } + @TestMetadata("hashTableWithForEach.kt") + public void testHashTableWithForEach() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/hashTableWithForEach.kt"); + } + @TestMetadata("helloWorld.kt") public void testHelloWorld() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/helloWorld.kt"); @@ -173,6 +178,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolve/stdlib/typeAliasDeserialization.kt"); } + @TestMetadata("typeAliasWithForEach.kt") + public void testTypeAliasWithForEach() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/typeAliasWithForEach.kt"); + } + @TestMetadata("typeParameterDerived.kt") public void testTypeParameterDerived() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/typeParameterDerived.kt");