Do not override collection stub, if the override is suspend

but the stub is not. The other way around should be OK.

 #KT-52237 Fixed
This commit is contained in:
Ilmir Usmanov
2022-05-04 23:33:28 +02:00
committed by teamcity
parent b19b265735
commit 4f53b085ec
11 changed files with 199 additions and 0 deletions
@@ -10613,6 +10613,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested
@@ -205,6 +205,7 @@ internal class CollectionStubMethodLowering(val context: JvmBackendContext) : Cl
if (superFun.name != overridingFun.name) return false
if (superFun.typeParameters.size != overridingFun.typeParameters.size) return false
if (superFun.valueParameters.size != overridingFun.valueParameters.size) return false
if (!superFun.isSuspend && overridingFun.isSuspend) return false
val typeChecker = createTypeCheckerState(superFun, overridingFun)
@@ -0,0 +1,54 @@
// WITH_STDLIB
import kotlin.coroutines.*
abstract class SuspendingMutableMap<K : Any, V : Any>(
protected val map: MutableMap<K, V>,
) : Map<K, V> {
abstract suspend fun clear()
override val entries: Set<Map.Entry<K, V>>
get() = TODO("Not yet implemented")
override val keys: Set<K>
get() = TODO("Not yet implemented")
override val size: Int
get() = TODO("Not yet implemented")
override val values: Collection<V>
get() = TODO("Not yet implemented")
override fun isEmpty(): Boolean {
TODO("Not yet implemented")
}
override fun get(key: K): V? {
TODO("Not yet implemented")
}
override fun containsValue(value: V): Boolean {
TODO("Not yet implemented")
}
override fun containsKey(key: K): Boolean {
TODO("Not yet implemented")
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
builder {
val m = mutableMapOf(1 to 1)
val map = object: SuspendingMutableMap<Int, Int>(m) {
override suspend fun clear() {
map.clear()
}
}
map.clear()
if (m.isNotEmpty()) error ("FAIL")
}
return "OK"
}
@@ -0,0 +1,52 @@
// WITH_STDLIB
import kotlin.coroutines.*
class SuspendingMutableMap<K : Any, V : Any>(
private val map: MutableMap<K, V>,
) : Map<K, V> {
suspend fun clear() {
map.clear()
}
override val entries: Set<Map.Entry<K, V>>
get() = TODO("Not yet implemented")
override val keys: Set<K>
get() = TODO("Not yet implemented")
override val size: Int
get() = TODO("Not yet implemented")
override val values: Collection<V>
get() = TODO("Not yet implemented")
override fun isEmpty(): Boolean {
TODO("Not yet implemented")
}
override fun get(key: K): V? {
TODO("Not yet implemented")
}
override fun containsValue(value: V): Boolean {
TODO("Not yet implemented")
}
override fun containsKey(key: K): Boolean {
TODO("Not yet implemented")
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
builder {
val m = mutableMapOf(1 to 1)
val map = SuspendingMutableMap(m)
map.clear()
if (m.isNotEmpty()) error ("FAIL")
}
return "OK"
}
@@ -10493,6 +10493,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested
@@ -10613,6 +10613,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested
@@ -8275,6 +8275,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/controlFlow")
@@ -7549,6 +7549,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested
@@ -7591,6 +7591,18 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested
@@ -6665,6 +6665,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/controlFlow")
@@ -8435,6 +8435,18 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
public void testLambdaWithMultipleParameters() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt");
}
@Test
@TestMetadata("mapSuspendAbstractClear.kt")
public void testMapSuspendAbstractClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendAbstractClear.kt");
}
@Test
@TestMetadata("mapSuspendClear.kt")
public void testMapSuspendClear() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/bridges/mapSuspendClear.kt");
}
}
@Nested