From 4dd1f9f4d62db0771b2ef763483ec93848bdb9e0 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Wed, 24 May 2023 14:44:09 +0200 Subject: [PATCH] [FIR] Set type arguments for callable reference in property delegation #KT-58555 Fixed --- .../jetbrains/kotlin/fir/builder/ConversionUtils.kt | 11 +++++++++++ .../box/callableReference/property/genericProperty.kt | 2 -- .../deepGenericDelegatedProperty.kt | 3 --- .../ir/serializationRegressions/genericProperty.kt | 2 -- .../declarations/genericDelegatedProperty.fir.ir.txt | 4 ++-- .../declarations/genericDelegatedProperty.fir.kt.txt | 4 ++-- .../irText/expressions/genericPropertyRef.fir.ir.txt | 4 ++-- .../irText/expressions/genericPropertyRef.fir.kt.txt | 4 ++-- .../types/genericDelegatedDeepProperty.fir.ir.txt | 2 +- .../types/genericDelegatedDeepProperty.fir.kt.txt | 2 +- 10 files changed, 21 insertions(+), 17 deletions(-) diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index 2f8e30a188b..76eb25fc0c9 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -44,11 +44,13 @@ import org.jetbrains.kotlin.fir.types.ConeStarProjection import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef +import org.jetbrains.kotlin.fir.types.builder.buildTypeProjectionWithVariance import org.jetbrains.kotlin.fir.types.impl.* import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.types.ConstantValueKind +import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.util.OperatorNameConventions import kotlin.contracts.ExperimentalContracts @@ -389,6 +391,15 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( FirImplicitKProperty1TypeRef(null, ConeStarProjection, ConeStarProjection) } } + this@generateAccessorsByDelegate.typeParameters.mapTo(typeArguments) { + buildTypeProjectionWithVariance { + source = fakeSource + variance = Variance.INVARIANT + typeRef = buildResolvedTypeRef { + type = ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) + } + } + } } delegateBuilder.delegateProvider = buildFunctionCall { diff --git a/compiler/testData/codegen/box/callableReference/property/genericProperty.kt b/compiler/testData/codegen/box/callableReference/property/genericProperty.kt index 6d7edba63be..aca545f3bc5 100644 --- a/compiler/testData/codegen/box/callableReference/property/genericProperty.kt +++ b/compiler/testData/codegen/box/callableReference/property/genericProperty.kt @@ -1,7 +1,5 @@ // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate //For KT-6020 -// KT-58555 -// IGNORE_BACKEND_K2: NATIVE import kotlin.reflect.KProperty1 import kotlin.reflect.KMutableProperty1 diff --git a/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt b/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt index b37c3dba663..c813906d14a 100644 --- a/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt +++ b/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt @@ -1,11 +1,8 @@ // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate // IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_NATIVE // SKIP_MANGLE_VERIFICATION //For KT-6020 // KT-24643: language version in K2 is >= 1.8 -// KT-58555 -// IGNORE_BACKEND_K2: NATIVE // MODULE: lib // FILE: lib.kt diff --git a/compiler/testData/codegen/box/ir/serializationRegressions/genericProperty.kt b/compiler/testData/codegen/box/ir/serializationRegressions/genericProperty.kt index 64f5201a7b1..94a512aa88f 100644 --- a/compiler/testData/codegen/box/ir/serializationRegressions/genericProperty.kt +++ b/compiler/testData/codegen/box/ir/serializationRegressions/genericProperty.kt @@ -1,8 +1,6 @@ // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate //For KT-6020 // KT-24643: language version in K2 is >= 1.8 -// KT-58555 -// IGNORE_BACKEND_K2: NATIVE // MODULE: lib // FILE: lib.kt diff --git a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.ir.txt b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.ir.txt index d66b97cd35a..4a05f6bb903 100644 --- a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.ir.txt +++ b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.ir.txt @@ -65,7 +65,7 @@ FILE fqName: fileName:/genericDelegatedProperty.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:.Delegate visibility:private [final,static]' type=.Delegate origin=null thisRef: GET_VAR ': .C.> declared in .' type=.C.> origin=null kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun (): kotlin.Int declared in ' setter='public final fun (: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KMutableProperty1<.C.>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE - <1>: + <1>: T of . FUN DELEGATED_PROPERTY_ACCESSOR name: visibility:public modality:FINAL ($receiver:.C.>, :kotlin.Int) returnType:kotlin.Unit correspondingProperty: PROPERTY name:genericDelegatedProperty visibility:public modality:FINAL [delegated,var] TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false @@ -76,5 +76,5 @@ FILE fqName: fileName:/genericDelegatedProperty.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:.Delegate visibility:private [final,static]' type=.Delegate origin=null thisRef: GET_VAR ': .C.> declared in .' type=.C.> origin=null kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun (): kotlin.Int declared in ' setter='public final fun (: kotlin.Int): kotlin.Unit declared in ' type=kotlin.reflect.KMutableProperty1<.C.>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE - <1>: + <1>: T of . newValue: GET_VAR ': kotlin.Int declared in .' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt index 23037eff964..3babc4f706a 100644 --- a/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt +++ b/compiler/testData/ir/irText/declarations/genericDelegatedProperty.fir.kt.txt @@ -26,8 +26,8 @@ object Delegate { var C.genericDelegatedProperty: Int /* by */ field = Delegate get(): Int { - return #genericDelegatedProperty$delegate.getValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/) + return #genericDelegatedProperty$delegate.getValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/) } set(: Int) { - #genericDelegatedProperty$delegate.setValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/, newValue = ) + #genericDelegatedProperty$delegate.setValue(thisRef = , kProp = ::genericDelegatedProperty/*()*/, newValue = ) } diff --git a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.ir.txt b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.ir.txt index d28e2f7b6e9..1a4520ff01d 100644 --- a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.ir.txt @@ -79,7 +79,7 @@ FILE fqName: fileName:/genericPropertyRef.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:.DVal visibility:private [final,static]' type=.DVal origin=null t: GET_VAR ': .Value.> declared in .' type=.Value.> origin=null p: PROPERTY_REFERENCE 'public final additionalText: kotlin.Int [delegated,val]' field=null getter='public final fun (): kotlin.Int declared in ' setter=null type=kotlin.reflect.KProperty1<.Value.>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE - <1>: + <1>: T of . PROPERTY name:additionalValue visibility:public modality:FINAL [delegated,val] FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:.DVal visibility:private [final,static] EXPRESSION_BODY @@ -95,7 +95,7 @@ FILE fqName: fileName:/genericPropertyRef.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:.DVal visibility:private [final,static]' type=.DVal origin=null t: GET_VAR ': .Value.> declared in .' type=.Value.> origin=null p: PROPERTY_REFERENCE 'public final additionalValue: kotlin.Int [delegated,val]' field=null getter='public final fun (): kotlin.Int declared in ' setter=null type=kotlin.reflect.KProperty1<.Value.>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE - <1>: + <1>: T of . CLASS CLASS name:DVal modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.DVal CONSTRUCTOR visibility:public <> (kmember:kotlin.Any) returnType:.DVal [primary] diff --git a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt index 92837ccb850..f41ebab2a94 100644 --- a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.kt.txt @@ -20,13 +20,13 @@ class Value { val Value.additionalText: Int /* by */ field = DVal(kmember = Value::text) get(): Int { - return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) + return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) } val Value.additionalValue: Int /* by */ field = DVal(kmember = Value::value) get(): Int { - return #additionalValue$delegate.getValue(t = , p = ::additionalValue/*()*/) + return #additionalValue$delegate.getValue(t = , p = ::additionalValue/*()*/) } class DVal { diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt index 84e873f6bc8..77d90b389f9 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.ir.txt @@ -369,4 +369,4 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:.additionalText$delegate..> visibility:private [final,static]' type=.additionalText$delegate..> origin=null t: GET_VAR ': .Value., .CR.>> declared in .' type=.Value., .CR.>> origin=null p: PROPERTY_REFERENCE 'public final additionalText: .P., T of .> [delegated,val]' field=null getter='public final fun (): .P., T of .> declared in ' setter=null type=kotlin.reflect.KProperty1<.Value., .CR.>>, .P., T of .>> origin=PROPERTY_REFERENCE_FOR_DELEGATE - <1>: + <1>: T of . diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt index 0a8e4f04b4c..09e8034d2cf 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.kt.txt @@ -141,5 +141,5 @@ val Value>.additionalText: P /* by */ () } get(): P { - return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) + return #additionalText$delegate.getValue(t = , p = ::additionalText/*()*/) }