Skip to content

Commit 916d81d

Browse files
dzharkovSpace Team
authored andcommitted
FIR2IR: Avoid generation of incorrect suspend adapter for custom implementation
^KT-82590 Fixed
1 parent 66a2d19 commit 916d81d

File tree

9 files changed

+7
-385
lines changed

9 files changed

+7
-385
lines changed

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ class AdapterGenerator(
551551
return this
552552
}
553553

554+
val preparedArgumentType = prepareArgumentTypeForSuspendConversion(argument)
555+
// No conversion should happen if an argument already satisfies the expected type requirements
556+
// NB: It's not just a fast path, but sometimes the presence adapter generation is incorrect (see KT-82590)
557+
if (preparedArgumentType.isSubtypeOf(expectedType, session)) return this
558+
554559
val unwrappedExpectedType = getFunctionTypeForPossibleSamType(expectedType) ?: expectedType
555560

556561
// Expect the expected type to be a suspend functional type.
@@ -559,7 +564,6 @@ class AdapterGenerator(
559564
}
560565
val expectedFunctionalType = unwrappedExpectedType.customFunctionTypeToSimpleFunctionType(session)
561566

562-
val preparedArgumentType = prepareArgumentTypeForSuspendConversion(argument)
563567
val invokeSymbol = findInvokeSymbol(expectedFunctionalType, preparedArgumentType) ?: return this
564568
val suspendConvertedType = unwrappedExpectedType.toIrType() as IrSimpleType
565569
return argument.convertWithOffsets { startOffset, endOffset ->

compiler/testData/codegen/box/funInterface/noConversionForSubtype.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
22
// IGNORE_IR_DESERIALIZATION_TEST: JS_IR, JS_IR_ES6
3-
// IGNORE_BACKEND_K2: ANY
43
// ISSUE: KT-82590
54

65
interface MyInterface

compiler/testData/codegen/box/funInterface/noConversionForSubtypeGeneric.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
22
// IGNORE_IR_DESERIALIZATION_TEST: JS_IR, JS_IR_ES6
3-
// IGNORE_BACKEND_K2: ANY
43
// ISSUE: KT-82590
54

65
interface MyInterface

compiler/testData/ir/irText/expressions/funInterface/noConversionForSubtype.fir.ir.txt

Lines changed: 0 additions & 123 deletions
This file was deleted.

compiler/testData/ir/irText/expressions/funInterface/noConversionForSubtype.fir.kt.txt

Lines changed: 0 additions & 63 deletions
This file was deleted.

compiler/testData/ir/irText/expressions/funInterface/noConversionForSubtype.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIR_IDENTICAL
12
// DONT_TARGET_EXACT_BACKEND: JS_IR
23
// ISSUE: KT-82590
34

0 commit comments

Comments
 (0)