From 5d3fe7547ae8d26503fc966ab688811bcd94e47f Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Tue, 18 Apr 2023 14:12:11 +0200 Subject: [PATCH] [IR] Fix mangling generic properties from IR-based descriptors For type parameters of generic properties, `DeclarationDescriptor#getContainingDeclaration` must return the property descriptor instead of the accessor function descriptor. ^KT-57436 Fixed --- .../jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt | 3 +++ .../ir/irText/declarations/genericDelegatedProperty.kt | 4 ++-- compiler/testData/ir/irText/declarations/kt35550.kt | 2 +- .../ir/irText/declarations/parameters/propertyAccessors.kt | 4 ++-- .../declarations/parameters/typeParameterBeforeBound.kt | 4 ++-- .../genericLocalClassConstructorReference.kt | 2 +- .../testData/ir/irText/expressions/castToTypeParameter.kt | 4 ++-- .../testData/ir/irText/expressions/genericPropertyCall.kt | 4 ++-- .../ir/irText/expressions/implicitCastToTypeParameter.kt | 4 ++-- .../ir/irText/expressions/typeParameterClassLiteral.kt | 4 ++-- compiler/testData/ir/irText/expressions/useImportedMember.kt | 3 --- .../irText/expressions/variableAsFunctionCallWithGenerics.kt | 5 +++-- .../testData/ir/irText/regressions/integerCoercionToT.kt | 4 ---- .../testData/ir/irText/types/genericDelegatedDeepProperty.kt | 2 +- 14 files changed, 23 insertions(+), 26 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt index 736c48b96a8..63c3ddaebd5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBasedDescriptors.kt @@ -1146,6 +1146,9 @@ fun IrErrorDeclaration.toIrBasedDescriptor() = IrBasedErrorDescriptor(this) @OptIn(ObsoleteDescriptorBasedAPI::class) private fun getContainingDeclaration(declaration: IrDeclaration): DeclarationDescriptor { val parent = declaration.parent + if (declaration is IrTypeParameter && parent is IrSimpleFunction) { + parent.correspondingPropertySymbol?.owner?.let { return it.toIrBasedDescriptor() } + } val parentDescriptor = (parent as IrSymbolOwner).let { if (it is IrDeclaration) it.toIrBasedDescriptor() else it.symbol.descriptor } diff --git a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.kt b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.kt index 81f54eca400..7a751718f84 100644 --- a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.kt +++ b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.kt @@ -1,5 +1,5 @@ -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 class C diff --git a/compiler/testData/ir/irText/declarations/kt35550.kt b/compiler/testData/ir/irText/declarations/kt35550.kt index adb3ff17938..93ec96f2eaf 100644 --- a/compiler/testData/ir/irText/declarations/kt35550.kt +++ b/compiler/testData/ir/irText/declarations/kt35550.kt @@ -1,5 +1,5 @@ // MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57754, KT-57436 +// ^ KT-57754 interface I { val T.id: T diff --git a/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.kt b/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.kt index 0e25db370e6..001edc65c7c 100644 --- a/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.kt +++ b/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 val test1 get() = 42 diff --git a/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt index 0fe4a6fb27e..33b91024f6a 100644 --- a/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt +++ b/compiler/testData/ir/irText/declarations/parameters/typeParameterBeforeBound.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 class Test1 diff --git a/compiler/testData/ir/irText/expressions/callableReferences/genericLocalClassConstructorReference.kt b/compiler/testData/ir/irText/expressions/callableReferences/genericLocalClassConstructorReference.kt index 7e915b754c3..01cfddd9d98 100644 --- a/compiler/testData/ir/irText/expressions/callableReferences/genericLocalClassConstructorReference.kt +++ b/compiler/testData/ir/irText/expressions/callableReferences/genericLocalClassConstructorReference.kt @@ -1,5 +1,5 @@ // MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57429, KT-57436 +// ^ KT-57429 open class L(val ll: LL) diff --git a/compiler/testData/ir/irText/expressions/castToTypeParameter.kt b/compiler/testData/ir/irText/expressions/castToTypeParameter.kt index 1fa1652c6c0..62054746084 100644 --- a/compiler/testData/ir/irText/expressions/castToTypeParameter.kt +++ b/compiler/testData/ir/irText/expressions/castToTypeParameter.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 fun castFun(x: Any) = x as T diff --git a/compiler/testData/ir/irText/expressions/genericPropertyCall.kt b/compiler/testData/ir/irText/expressions/genericPropertyCall.kt index 3677e48012f..cb93075b7fb 100644 --- a/compiler/testData/ir/irText/expressions/genericPropertyCall.kt +++ b/compiler/testData/ir/irText/expressions/genericPropertyCall.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 val T.id get() = this diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt index 7e973dd11ee..4439fb69426 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.kt @@ -1,5 +1,5 @@ -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 inline fun Any.test1(): T? = if (this is T) this else null diff --git a/compiler/testData/ir/irText/expressions/typeParameterClassLiteral.kt b/compiler/testData/ir/irText/expressions/typeParameterClassLiteral.kt index 9d2f1ff1ff8..8e89aab4762 100644 --- a/compiler/testData/ir/irText/expressions/typeParameterClassLiteral.kt +++ b/compiler/testData/ir/irText/expressions/typeParameterClassLiteral.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^KT-57436 +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 inline fun classRefFun() = T::class diff --git a/compiler/testData/ir/irText/expressions/useImportedMember.kt b/compiler/testData/ir/irText/expressions/useImportedMember.kt index 5ab9867e31b..b8f77abc1f6 100644 --- a/compiler/testData/ir/irText/expressions/useImportedMember.kt +++ b/compiler/testData/ir/irText/expressions/useImportedMember.kt @@ -1,6 +1,3 @@ -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 - import C.f import C.p import C.ext diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.kt b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.kt index d0b4d2f5389..90951a985a7 100644 --- a/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.kt +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.kt @@ -1,6 +1,7 @@ // FIR_IDENTICAL -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57429 + +// MUTE_SIGNATURE_COMPARISON_K2: JS_IR +// ^ KT-57818 val T.gk: () -> T get() = { -> this } diff --git a/compiler/testData/ir/irText/regressions/integerCoercionToT.kt b/compiler/testData/ir/irText/regressions/integerCoercionToT.kt index 364806c5209..403eed60555 100644 --- a/compiler/testData/ir/irText/regressions/integerCoercionToT.kt +++ b/compiler/testData/ir/irText/regressions/integerCoercionToT.kt @@ -1,9 +1,5 @@ // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 - -// MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57436 - interface CPointed inline fun CPointed.reinterpret(): T = TODO() diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.kt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.kt index c747408402c..bcfbc359c31 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.kt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.kt @@ -1,7 +1,7 @@ // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate // MUTE_SIGNATURE_COMPARISON_K2: ANY -// ^ KT-57429, KT-57436 +// ^ KT-57429 import kotlin.reflect.KProperty1 import kotlin.reflect.KMutableProperty1