[FIR] Set type arguments for callable reference in property delegation

#KT-58555 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-24 14:44:09 +02:00
committed by Space Team
parent bdfc2c33c5
commit 4dd1f9f4d6
10 changed files with 21 additions and 17 deletions
@@ -44,11 +44,13 @@ import org.jetbrains.kotlin.fir.types.ConeStarProjection
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef 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.fir.types.impl.*
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.ConstantValueKind
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.expressions.OperatorConventions import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.OperatorNameConventions
import kotlin.contracts.ExperimentalContracts import kotlin.contracts.ExperimentalContracts
@@ -389,6 +391,15 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
FirImplicitKProperty1TypeRef(null, ConeStarProjection, ConeStarProjection) 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 { delegateBuilder.delegateProvider = buildFunctionCall {
@@ -1,7 +1,5 @@
// !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate
//For KT-6020 //For KT-6020
// KT-58555
// IGNORE_BACKEND_K2: NATIVE
import kotlin.reflect.KProperty1 import kotlin.reflect.KProperty1
import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KMutableProperty1
@@ -1,11 +1,8 @@
// !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate
// IGNORE_BACKEND: WASM // IGNORE_BACKEND: WASM
// WASM_MUTE_REASON: IGNORED_IN_NATIVE
// SKIP_MANGLE_VERIFICATION // SKIP_MANGLE_VERIFICATION
//For KT-6020 //For KT-6020
// KT-24643: language version in K2 is >= 1.8 // KT-24643: language version in K2 is >= 1.8
// KT-58555
// IGNORE_BACKEND_K2: NATIVE
// MODULE: lib // MODULE: lib
// FILE: lib.kt // FILE: lib.kt
@@ -1,8 +1,6 @@
// !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate // !LANGUAGE: -ForbidUsingExtensionPropertyTypeParameterInDelegate
//For KT-6020 //For KT-6020
// KT-24643: language version in K2 is >= 1.8 // KT-24643: language version in K2 is >= 1.8
// KT-58555
// IGNORE_BACKEND_K2: NATIVE
// MODULE: lib // MODULE: lib
// FILE: lib.kt // FILE: lib.kt
@@ -65,7 +65,7 @@ FILE fqName:<root> fileName:/genericDelegatedProperty.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:<root>.Delegate visibility:private [final,static]' type=<root>.Delegate origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:<root>.Delegate visibility:private [final,static]' type=<root>.Delegate origin=null
thisRef: GET_VAR '<this>: <root>.C<T of <root>.<get-genericDelegatedProperty>> declared in <root>.<get-genericDelegatedProperty>' type=<root>.C<T of <root>.<get-genericDelegatedProperty>> origin=null thisRef: GET_VAR '<this>: <root>.C<T of <root>.<get-genericDelegatedProperty>> declared in <root>.<get-genericDelegatedProperty>' type=<root>.C<T of <root>.<get-genericDelegatedProperty>> origin=null
kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun <get-genericDelegatedProperty> <T> (): kotlin.Int declared in <root>' setter='public final fun <set-genericDelegatedProperty> <T> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty1<<root>.C<T of <root>.<get-genericDelegatedProperty>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun <get-genericDelegatedProperty> <T> (): kotlin.Int declared in <root>' setter='public final fun <set-genericDelegatedProperty> <T> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty1<<root>.C<T of <root>.<get-genericDelegatedProperty>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
<1>: <none> <1>: T of <root>.<get-genericDelegatedProperty>
FUN DELEGATED_PROPERTY_ACCESSOR name:<set-genericDelegatedProperty> visibility:public modality:FINAL <T> ($receiver:<root>.C<T of <root>.<set-genericDelegatedProperty>>, <set-?>:kotlin.Int) returnType:kotlin.Unit FUN DELEGATED_PROPERTY_ACCESSOR name:<set-genericDelegatedProperty> visibility:public modality:FINAL <T> ($receiver:<root>.C<T of <root>.<set-genericDelegatedProperty>>, <set-?>:kotlin.Int) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:genericDelegatedProperty visibility:public modality:FINAL [delegated,var] correspondingProperty: PROPERTY name:genericDelegatedProperty visibility:public modality:FINAL [delegated,var]
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
@@ -76,5 +76,5 @@ FILE fqName:<root> fileName:/genericDelegatedProperty.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:<root>.Delegate visibility:private [final,static]' type=<root>.Delegate origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:genericDelegatedProperty$delegate type:<root>.Delegate visibility:private [final,static]' type=<root>.Delegate origin=null
thisRef: GET_VAR '<this>: <root>.C<T of <root>.<set-genericDelegatedProperty>> declared in <root>.<set-genericDelegatedProperty>' type=<root>.C<T of <root>.<set-genericDelegatedProperty>> origin=null thisRef: GET_VAR '<this>: <root>.C<T of <root>.<set-genericDelegatedProperty>> declared in <root>.<set-genericDelegatedProperty>' type=<root>.C<T of <root>.<set-genericDelegatedProperty>> origin=null
kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun <get-genericDelegatedProperty> <T> (): kotlin.Int declared in <root>' setter='public final fun <set-genericDelegatedProperty> <T> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty1<<root>.C<T of <root>.<set-genericDelegatedProperty>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE kProp: PROPERTY_REFERENCE 'public final genericDelegatedProperty: kotlin.Int [delegated,var]' field=null getter='public final fun <get-genericDelegatedProperty> <T> (): kotlin.Int declared in <root>' setter='public final fun <set-genericDelegatedProperty> <T> (<set-?>: kotlin.Int): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty1<<root>.C<T of <root>.<set-genericDelegatedProperty>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
<1>: <none> <1>: T of <root>.<set-genericDelegatedProperty>
newValue: GET_VAR '<set-?>: kotlin.Int declared in <root>.<set-genericDelegatedProperty>' type=kotlin.Int origin=null newValue: GET_VAR '<set-?>: kotlin.Int declared in <root>.<set-genericDelegatedProperty>' type=kotlin.Int origin=null
@@ -26,8 +26,8 @@ object Delegate {
var <T : Any?> C<T>.genericDelegatedProperty: Int /* by */ var <T : Any?> C<T>.genericDelegatedProperty: Int /* by */
field = Delegate field = Delegate
get(): Int { get(): Int {
return #genericDelegatedProperty$delegate.getValue(thisRef = <this>, kProp = ::genericDelegatedProperty/*</* null */>()*/) return #genericDelegatedProperty$delegate.getValue(thisRef = <this>, kProp = ::genericDelegatedProperty/*<T>()*/)
} }
set(<set-?>: Int) { set(<set-?>: Int) {
#genericDelegatedProperty$delegate.setValue(thisRef = <this>, kProp = ::genericDelegatedProperty/*</* null */>()*/, newValue = <set-?>) #genericDelegatedProperty$delegate.setValue(thisRef = <this>, kProp = ::genericDelegatedProperty/*<T>()*/, newValue = <set-?>)
} }
@@ -79,7 +79,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=null
t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>> declared in <root>.<get-additionalText>' type=<root>.Value<T of <root>.<get-additionalText>> origin=null t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>> declared in <root>.<get-additionalText>' type=<root>.Value<T of <root>.<get-additionalText>> origin=null
p: PROPERTY_REFERENCE 'public final additionalText: kotlin.Int [delegated,val]' field=null getter='public final fun <get-additionalText> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalText>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE p: PROPERTY_REFERENCE 'public final additionalText: kotlin.Int [delegated,val]' field=null getter='public final fun <get-additionalText> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalText>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
<1>: <none> <1>: T of <root>.<get-additionalText>
PROPERTY name:additionalValue visibility:public modality:FINAL [delegated,val] PROPERTY name:additionalValue visibility:public modality:FINAL [delegated,val]
FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static] FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]
EXPRESSION_BODY EXPRESSION_BODY
@@ -95,7 +95,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=null
t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalValue>> declared in <root>.<get-additionalValue>' type=<root>.Value<T of <root>.<get-additionalValue>> origin=null t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalValue>> declared in <root>.<get-additionalValue>' type=<root>.Value<T of <root>.<get-additionalValue>> origin=null
p: PROPERTY_REFERENCE 'public final additionalValue: kotlin.Int [delegated,val]' field=null getter='public final fun <get-additionalValue> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalValue>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE p: PROPERTY_REFERENCE 'public final additionalValue: kotlin.Int [delegated,val]' field=null getter='public final fun <get-additionalValue> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalValue>>, kotlin.Int> origin=PROPERTY_REFERENCE_FOR_DELEGATE
<1>: <none> <1>: T of <root>.<get-additionalValue>
CLASS CLASS name:DVal modality:FINAL visibility:public superTypes:[kotlin.Any] CLASS CLASS name:DVal modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.DVal $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.DVal
CONSTRUCTOR visibility:public <> (kmember:kotlin.Any) returnType:<root>.DVal [primary] CONSTRUCTOR visibility:public <> (kmember:kotlin.Any) returnType:<root>.DVal [primary]
@@ -20,13 +20,13 @@ class Value<T : Any?> {
val <T : Any?> Value<T>.additionalText: Int /* by */ val <T : Any?> Value<T>.additionalText: Int /* by */
field = DVal(kmember = Value::text) field = DVal(kmember = Value::text)
get(): Int { get(): Int {
return #additionalText$delegate.getValue(t = <this>, p = ::additionalText/*</* null */>()*/) return #additionalText$delegate.getValue(t = <this>, p = ::additionalText/*<T>()*/)
} }
val <T : Any?> Value<T>.additionalValue: Int /* by */ val <T : Any?> Value<T>.additionalValue: Int /* by */
field = DVal(kmember = Value::value) field = DVal(kmember = Value::value)
get(): Int { get(): Int {
return #additionalValue$delegate.getValue(t = <this>, p = ::additionalValue/*</* null */>()*/) return #additionalValue$delegate.getValue(t = <this>, p = ::additionalValue/*<T>()*/)
} }
class DVal { class DVal {
@@ -369,4 +369,4 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final,static]' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final,static]' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> declared in <root>.<get-additionalText>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null t: GET_VAR '<this>: <root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> declared in <root>.<get-additionalText>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null
p: PROPERTY_REFERENCE 'public final additionalText: <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> [delegated,val]' field=null getter='public final fun <get-additionalText> <T> (): <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>>> origin=PROPERTY_REFERENCE_FOR_DELEGATE p: PROPERTY_REFERENCE 'public final additionalText: <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> [delegated,val]' field=null getter='public final fun <get-additionalText> <T> (): <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> declared in <root>' setter=null type=kotlin.reflect.KProperty1<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>>> origin=PROPERTY_REFERENCE_FOR_DELEGATE
<1>: <none> <1>: T of <root>.<get-additionalText>
@@ -141,5 +141,5 @@ val <T : Any?> Value<T, CR<T>>.additionalText: P<T, T> /* by */
<no name provided>() <no name provided>()
} }
get(): P<T, T> { get(): P<T, T> {
return #additionalText$delegate.getValue(t = <this>, p = ::additionalText/*</* null */>()*/) return #additionalText$delegate.getValue(t = <this>, p = ::additionalText/*<T>()*/)
} }