IR: fix thisReceiver parameter type for function classes
Incorrect builder was used at line 269, which led to non-sensible type in `IrClass.thisReceiver` for function types, such as `SuspendFunction1<SuspendFunction1, SuspendFunction1>` in the linked issue. Avoid creating types manually completely to simplify this code and fix the bug. #KT-49168 Fixed
This commit is contained in:
+6
@@ -9762,6 +9762,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+5
-2
@@ -32,7 +32,10 @@ import org.jetbrains.kotlin.ir.types.*
|
|||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder
|
||||||
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
||||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
|
import org.jetbrains.kotlin.ir.util.functions
|
||||||
|
import org.jetbrains.kotlin.ir.util.referenceClassifier
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
@@ -54,7 +57,7 @@ class IrBuiltInsOverDescriptors(
|
|||||||
get() =
|
get() =
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (_functionFactory == null) {
|
if (_functionFactory == null) {
|
||||||
_functionFactory = IrDescriptorBasedFunctionFactory(this, symbolTable)
|
_functionFactory = IrDescriptorBasedFunctionFactory(this, symbolTable, typeTranslator)
|
||||||
}
|
}
|
||||||
_functionFactory!!
|
_functionFactory!!
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-19
@@ -85,6 +85,7 @@ abstract class IrAbstractDescriptorBasedFunctionFactory {
|
|||||||
class IrDescriptorBasedFunctionFactory(
|
class IrDescriptorBasedFunctionFactory(
|
||||||
private val irBuiltIns: IrBuiltInsOverDescriptors,
|
private val irBuiltIns: IrBuiltInsOverDescriptors,
|
||||||
private val symbolTable: SymbolTable,
|
private val symbolTable: SymbolTable,
|
||||||
|
private val typeTranslator: TypeTranslator,
|
||||||
getPackageFragment: ((PackageFragmentDescriptor) -> IrPackageFragment)? = null,
|
getPackageFragment: ((PackageFragmentDescriptor) -> IrPackageFragment)? = null,
|
||||||
// Needed for JS and Wasm backends to "preload" interfaces that can referenced during lowerings
|
// Needed for JS and Wasm backends to "preload" interfaces that can referenced during lowerings
|
||||||
private val referenceFunctionsWhenKFunctionAreReferenced: Boolean = false,
|
private val referenceFunctionsWhenKFunctionAreReferenced: Boolean = false,
|
||||||
@@ -257,29 +258,16 @@ class IrDescriptorBasedFunctionFactory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrClass.createThisReceiver(descriptorFactory: FunctionDescriptorFactory): IrValueParameter {
|
private fun createThisReceiver(descriptorFactory: FunctionDescriptorFactory): IrValueParameter {
|
||||||
val vDescriptor = descriptorFactory.classReceiverParameterDescriptor()
|
val descriptor = descriptorFactory.classReceiverParameterDescriptor()
|
||||||
val vSymbol = IrValueParameterSymbolImpl(vDescriptor)
|
return irFactory.createValueParameter(
|
||||||
val type = with(IrSimpleTypeBuilder()) {
|
offset, offset, classOrigin, IrValueParameterSymbolImpl(descriptor), SpecialNames.THIS, -1,
|
||||||
classifier = symbol
|
typeTranslator.translateType(descriptor.type), null,
|
||||||
arguments = typeParameters.run {
|
|
||||||
val builder = IrSimpleTypeBuilder()
|
|
||||||
mapTo(ArrayList(size)) {
|
|
||||||
builder.classifier = it.symbol
|
|
||||||
buildTypeProjection()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buildSimpleType()
|
|
||||||
}
|
|
||||||
val vDeclaration = irFactory.createValueParameter(
|
|
||||||
offset, offset, classOrigin, vSymbol, SpecialNames.THIS, -1, type, null,
|
|
||||||
isCrossinline = false,
|
isCrossinline = false,
|
||||||
isNoinline = false,
|
isNoinline = false,
|
||||||
isHidden = false,
|
isHidden = false,
|
||||||
isAssignable = false
|
isAssignable = false
|
||||||
)
|
)
|
||||||
|
|
||||||
return vDeclaration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrClass.createMembers(isK: Boolean, isSuspend: Boolean, descriptorFactory: FunctionDescriptorFactory) {
|
private fun IrClass.createMembers(isK: Boolean, isSuspend: Boolean, descriptorFactory: FunctionDescriptorFactory) {
|
||||||
@@ -435,7 +423,7 @@ class IrDescriptorBasedFunctionFactory(
|
|||||||
|
|
||||||
val r = klass.createTypeParameters(n, descriptorFactory)
|
val r = klass.createTypeParameters(n, descriptorFactory)
|
||||||
|
|
||||||
klass.thisReceiver = klass.createThisReceiver(descriptorFactory).also { it.parent = klass }
|
klass.thisReceiver = createThisReceiver(descriptorFactory).also { it.parent = klass }
|
||||||
|
|
||||||
klass.superTypes = listOf(with(IrSimpleTypeBuilder()) {
|
klass.superTypes = listOf(with(IrSimpleTypeBuilder()) {
|
||||||
classifier = baseClass
|
classifier = baseClass
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSeria
|
|||||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr
|
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
||||||
@@ -56,7 +55,6 @@ import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
|
|||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
|
import org.jetbrains.kotlin.library.impl.BuiltInsPlatform
|
||||||
import org.jetbrains.kotlin.library.impl.buildKotlinLibrary
|
import org.jetbrains.kotlin.library.impl.buildKotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.resolver.KotlinResolvedLibrary
|
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||||
import org.jetbrains.kotlin.progress.IncrementalNextRoundException
|
import org.jetbrains.kotlin.progress.IncrementalNextRoundException
|
||||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
|
||||||
@@ -429,6 +427,7 @@ fun getIrModuleInfoForKlib(
|
|||||||
irBuiltIns.functionFactory = IrDescriptorBasedFunctionFactory(
|
irBuiltIns.functionFactory = IrDescriptorBasedFunctionFactory(
|
||||||
irBuiltIns,
|
irBuiltIns,
|
||||||
symbolTable,
|
symbolTable,
|
||||||
|
typeTranslator,
|
||||||
if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null,
|
if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
@@ -483,6 +482,7 @@ fun getIrModuleInfoForSourceFiles(
|
|||||||
IrDescriptorBasedFunctionFactory(
|
IrDescriptorBasedFunctionFactory(
|
||||||
irBuiltIns,
|
irBuiltIns,
|
||||||
symbolTable,
|
symbolTable,
|
||||||
|
psi2IrContext.typeTranslator,
|
||||||
if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null,
|
if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// IGNORE_LIGHT_ANALYSIS
|
||||||
|
|
||||||
|
import helpers.*
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
|
||||||
|
fun interface Print {
|
||||||
|
suspend fun print(msg: String): String
|
||||||
|
}
|
||||||
|
|
||||||
|
object Context : Print by Print(::id)
|
||||||
|
|
||||||
|
fun id(x: String): String = x
|
||||||
|
|
||||||
|
fun builder(c: suspend () -> Unit) {
|
||||||
|
c.startCoroutine(EmptyContinuation)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var result = "Fail"
|
||||||
|
builder {
|
||||||
|
result = Context.print("OK")
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
+6
@@ -9684,6 +9684,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+6
@@ -9762,6 +9762,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+5
@@ -7230,6 +7230,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt24135.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt24135.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void ignoreKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("suspendFunctionAsSupertype.kt")
|
@TestMetadata("suspendFunctionAsSupertype.kt")
|
||||||
public void ignoreSuspendFunctionAsSupertype() throws Exception {
|
public void ignoreSuspendFunctionAsSupertype() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt");
|
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -6752,6 +6752,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -5981,6 +5981,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt");
|
||||||
|
|||||||
+6
@@ -6998,6 +6998,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
+6
@@ -6956,6 +6956,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
runTest("compiler/testData/codegen/box/coroutines/kt46813.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt49168.kt")
|
||||||
|
public void testKt49168() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/kt49168.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("lastExpressionIsLoop.kt")
|
@TestMetadata("lastExpressionIsLoop.kt")
|
||||||
public void testLastExpressionIsLoop() throws Exception {
|
public void testLastExpressionIsLoop() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user