[FIR] Fix generating this reference in delegated accessors

There was a problem with delegated extension property with dispatch
  receiver that `this` in `getValue` call was set to dispatch receiver
  instead of extension one
This commit is contained in:
Dmitriy Novozhilov
2021-02-20 15:26:01 +03:00
committed by TeamCityServer
parent 4e5647090e
commit ea2783eace
9 changed files with 15 additions and 159 deletions
@@ -309,8 +309,14 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
* And for this case we can pass isForDelegateProviderCall to this reference
* generator function
*/
fun thisRef(isForDelegateProviderCall: Boolean = false): FirExpression =
fun thisRef(forDispatchReceiver: Boolean = false): FirExpression =
when {
isExtension && !forDispatchReceiver -> buildThisReceiverExpression {
source = fakeSource
calleeReference = buildImplicitThisReference {
boundSymbol = this@generateAccessorsByDelegate.symbol
}
}
ownerSymbol != null -> buildThisReceiverExpression {
source = fakeSource
calleeReference = buildImplicitThisReference {
@@ -321,12 +327,6 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
type = ownerSymbol.constructStarProjectedType(typeParameterNumber)
}
}
isExtension && !isForDelegateProviderCall -> buildThisReceiverExpression {
source = fakeSource
calleeReference = buildImplicitThisReference {
boundSymbol = this@generateAccessorsByDelegate.symbol
}
}
else -> buildConstExpression(null, ConstantValueKind.Null, null)
}
@@ -336,7 +336,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
resolvedSymbol = delegateFieldSymbol
}
if (ownerSymbol != null) {
dispatchReceiver = thisRef()
dispatchReceiver = thisRef(forDispatchReceiver = true)
}
}
@@ -373,7 +373,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate(
source = fakeSource
name = PROVIDE_DELEGATE
}
argumentList = buildBinaryArgumentList(thisRef(isForDelegateProviderCall = true), propertyRef())
argumentList = buildBinaryArgumentList(thisRef(forDispatchReceiver = true), propertyRef())
}
delegate = delegateBuilder.build()
if (stubMode) return
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.reflect.KProperty
class Delegate {
@@ -1,6 +1,5 @@
// !LANGUAGE: -NewInference
// IGNORE_BACKEND_FIR: JVM_IR
inline operator fun Double.provideDelegate(thisRef: Any?, kProp: Any?) = this.toLong()
inline operator fun Long.getValue(thisRef: Any?, kProp: Any?) = this.toInt()
@@ -59,4 +58,4 @@ fun box(): String {
x.test(intArray)
return "OK"
}
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
object Host {
@@ -13,4 +12,4 @@ object Host {
val ok = "O".plusK
}
fun box(): String = Host.ok
fun box(): String = Host.ok
@@ -1,6 +1,5 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: PROPERTY_REFERENCES
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: NATIVE
//For KT-6020
@@ -59,4 +58,4 @@ fun box(): String {
val p = Value("O", CR("K"))
val rr = p.additionalText
return rr.p1 + rr.p2
}
}
@@ -1,39 +0,0 @@
object Host {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
class StringDelegate {
constructor(s: String) /* primary */ {
super/*Any*/()
/* <init>() */
}
val s: String
field = s
get
operator fun getValue(receiver: String, p: Any): String {
return receiver.plus(other = <this>.<get-s>())
}
}
operator fun String.provideDelegate(host: Any?, p: Any): StringDelegate {
return StringDelegate(s = <this>)
}
val String.plusK: String /* by */
field = (<this>, "K").provideDelegate(host = <this>, p = Host::plusK)
get(): String {
return <this>.#plusK$delegate.getValue(receiver = <this>, p = Host::plusK)
}
val ok: String
field = (<this>, "O").<get-plusK>()
get
}
@@ -1,102 +0,0 @@
FILE fqName:<root> fileName:/memberExtension.kt
CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host
CONSTRUCTOR visibility:private <> () returnType:<root>.Host [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]'
CLASS CLASS name:StringDelegate modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host.StringDelegate
CONSTRUCTOR visibility:public <> (s:kotlin.String) returnType:<root>.Host.StringDelegate [primary]
VALUE_PARAMETER name:s index:0 type:kotlin.String
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:StringDelegate modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:s visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final]
EXPRESSION_BODY
GET_VAR 's: kotlin.String declared in <root>.Host.StringDelegate.<init>' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-s> visibility:public modality:FINAL <> ($this:<root>.Host.StringDelegate) returnType:kotlin.String
correspondingProperty: PROPERTY name:s visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host.StringDelegate
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-s> (): kotlin.String declared in <root>.Host.StringDelegate'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Host.StringDelegate declared in <root>.Host.StringDelegate.<get-s>' type=<root>.Host.StringDelegate origin=null
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.Host.StringDelegate, receiver:kotlin.String, p:kotlin.Any) returnType:kotlin.String [operator]
$this: VALUE_PARAMETER name:<this> type:<root>.Host.StringDelegate
VALUE_PARAMETER name:receiver index:0 type:kotlin.String
VALUE_PARAMETER name:p index:1 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun getValue (receiver: kotlin.String, p: kotlin.Any): kotlin.String [operator] declared in <root>.Host.StringDelegate'
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS
$this: GET_VAR 'receiver: kotlin.String declared in <root>.Host.StringDelegate.getValue' type=kotlin.String origin=null
other: CALL 'public final fun <get-s> (): kotlin.String declared in <root>.Host.StringDelegate' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Host.StringDelegate declared in <root>.Host.StringDelegate.getValue' type=<root>.Host.StringDelegate origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:provideDelegate visibility:public modality:FINAL <> ($this:<root>.Host, $receiver:kotlin.String, host:kotlin.Any?, p:kotlin.Any) returnType:<root>.Host.StringDelegate [operator]
$this: VALUE_PARAMETER name:<this> type:<root>.Host
$receiver: VALUE_PARAMETER name:<this> type:kotlin.String
VALUE_PARAMETER name:host index:0 type:kotlin.Any?
VALUE_PARAMETER name:p index:1 type:kotlin.Any
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): <root>.Host.StringDelegate [operator] declared in <root>.Host'
CONSTRUCTOR_CALL 'public constructor <init> (s: kotlin.String) [primary] declared in <root>.Host.StringDelegate' type=<root>.Host.StringDelegate origin=null
s: GET_VAR '<this>: kotlin.String declared in <root>.Host.provideDelegate' type=kotlin.String origin=null
PROPERTY name:plusK visibility:public modality:FINAL [delegated,val]
FIELD PROPERTY_DELEGATE name:plusK$delegate type:<root>.Host.StringDelegate visibility:private [final]
EXPRESSION_BODY
CALL 'public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): <root>.Host.StringDelegate [operator] declared in <root>.Host' type=<root>.Host.StringDelegate origin=null
$this: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
$receiver: CONST String type=kotlin.String value="K"
host: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field=null getter='public final fun <get-plusK> (): kotlin.String declared in <root>.Host' setter=null type=kotlin.reflect.KProperty2<kotlin.String, <root>.Host, kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-plusK> visibility:public modality:FINAL <> ($this:<root>.Host, $receiver:kotlin.String) returnType:kotlin.String
correspondingProperty: PROPERTY name:plusK visibility:public modality:FINAL [delegated,val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host
$receiver: VALUE_PARAMETER name:<this> type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-plusK> (): kotlin.String declared in <root>.Host'
CALL 'public final fun getValue (receiver: kotlin.String, p: kotlin.Any): kotlin.String [operator] declared in <root>.Host.StringDelegate' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:plusK$delegate type:<root>.Host.StringDelegate visibility:private [final]' type=<root>.Host.StringDelegate origin=null
receiver: GET_VAR '<this>: <root>.Host declared in <root>.Host.<get-plusK>' type=<root>.Host origin=null
receiver: GET_VAR '<this>: <root>.Host declared in <root>.Host.<get-plusK>' type=<root>.Host origin=null
p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field=null getter='public final fun <get-plusK> (): kotlin.String declared in <root>.Host' setter=null type=kotlin.reflect.KProperty2<kotlin.String, <root>.Host, kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE
PROPERTY name:ok visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]
EXPRESSION_BODY
CALL 'public final fun <get-plusK> (): kotlin.String declared in <root>.Host' type=kotlin.String origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
$receiver: CONST String type=kotlin.String value="O"
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ok> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:kotlin.String
correspondingProperty: PROPERTY name:ok visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-ok> (): kotlin.String declared in <root>.Host'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Host declared in <root>.Host.<get-ok>' type=<root>.Host origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
object Host {
class StringDelegate(val s: String) {
operator fun getValue(receiver: String, p: Any) = receiver + s
@@ -281,7 +281,7 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepO$delegate type:<root>.additionalText$delegate.<no name provided>.deepO$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final]' type=<root>.additionalText$delegate.<no name provided>.deepO$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
receiver: TYPE_OP type=<root>.additionalText$delegate.<no name provided> origin=IMPLICIT_CAST typeOperand=<root>.additionalText$delegate.<no name provided>
GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepO>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
t: GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepO>' 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>.additionalText$delegate.<no name provided>.<get-deepO>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null
p: PROPERTY_REFERENCE 'private final deepO: T of <root>.<get-additionalText> [delegated,val]' field=null getter='public final fun <get-deepO> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>' setter=null type=kotlin.reflect.KProperty2<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, *, T of <root>.<get-additionalText>> origin=PROPERTY_REFERENCE_FOR_DELEGATE
PROPERTY name:deepK visibility:private modality:FINAL [delegated,val]
FIELD PROPERTY_DELEGATE name:deepK$delegate type:<root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final]
@@ -328,7 +328,7 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepK$delegate type:<root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided><T of <root>.<get-additionalText>> visibility:private [final]' type=<root>.additionalText$delegate.<no name provided>.deepK$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
receiver: TYPE_OP type=<root>.additionalText$delegate.<no name provided> origin=IMPLICIT_CAST typeOperand=<root>.additionalText$delegate.<no name provided>
GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepK>' type=<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> origin=null
t: GET_VAR '<this>: <root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>> declared in <root>.additionalText$delegate.<no name provided>.<get-deepK>' 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>.additionalText$delegate.<no name provided>.<get-deepK>' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>> origin=null
p: PROPERTY_REFERENCE 'private final deepK: T of <root>.<get-additionalText> [delegated,val]' field=null getter='public final fun <get-deepK> (): T of <root>.<get-additionalText> declared in <root>.additionalText$delegate.<no name provided>' setter=null type=kotlin.reflect.KProperty2<<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, *, T of <root>.<get-additionalText>> origin=PROPERTY_REFERENCE_FOR_DELEGATE
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.additionalText$delegate.<no name provided><T of <root>.<get-additionalText>>, t:<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>, p:kotlin.reflect.KProperty<*>) returnType:<root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> [operator]
overridden: