FIR2IR: generate type arguments in delegation calls

This commit is contained in:
Mikhail Glukhikh
2021-12-03 13:40:44 +03:00
parent c57df1ac40
commit 85240bdb06
8 changed files with 32 additions and 21 deletions
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
import org.jetbrains.kotlin.ir.types.isNothing
import org.jetbrains.kotlin.ir.types.isUnit
import org.jetbrains.kotlin.name.ClassId
@@ -202,6 +203,16 @@ class DelegatedMemberGenerator(
delegateFunction.valueParameters.forEach {
putValueArgument(it.index, IrGetValueImpl(startOffset, endOffset, it.type, it.symbol))
}
superFunction.typeParameters.forEach {
putTypeArgument(
it.index, IrSimpleTypeImpl(
delegateFunction.typeParameters[it.index].symbol,
hasQuestionMark = false,
arguments = emptyList(),
annotations = emptyList()
)
)
}
}
if (superFunction.returnType.isUnit() || superFunction.returnType.isNothing()) {
body.statements.add(irCall)
@@ -55,7 +55,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:b index:1 type:B of <root>.Test1.foo
BLOCK_BODY
CALL 'public abstract fun foo <B> (a: A of <root>.IBase, b: B of <root>.IBase.foo): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<B>: <none>
<B>: B of <root>.Test1.foo
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<E of <root>.Test1> visibility:local [final]' type=<root>.IBase<E of <root>.Test1> origin=null
receiver: GET_VAR '<this>: <root>.Test1<E of <root>.Test1> declared in <root>.Test1.foo' type=<root>.Test1<E of <root>.Test1> origin=null
a: GET_VAR 'a: E of <root>.Test1 declared in <root>.Test1.foo' type=E of <root>.Test1 origin=null
@@ -73,7 +73,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-id> <C> (): kotlin.collections.Map<E of <root>.Test1, C of <root>.Test1.<get-id>>? declared in <root>.Test1'
CALL 'public abstract fun <get-id> <C> (): kotlin.collections.Map<A of <root>.IBase, C of <root>.IBase.<get-id>>? declared in <root>.IBase' type=kotlin.collections.Map<E of <root>.Test1, C of <root>.Test1.<get-id>>? origin=null
<C>: <none>
<C>: C of <root>.Test1.<get-id>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<E of <root>.Test1> visibility:local [final]' type=<root>.IBase<E of <root>.Test1> origin=null
receiver: GET_VAR '<this>: <root>.Test1<E of <root>.Test1> declared in <root>.Test1.<get-id>' type=<root>.Test1<E of <root>.Test1> origin=null
$receiver: GET_VAR '<this>: C of <root>.Test1.<get-id> declared in <root>.Test1.<get-id>' type=C of <root>.Test1.<get-id> origin=null
@@ -90,7 +90,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-x> <D> (): D of <root>.Test1.<get-x>? declared in <root>.Test1'
CALL 'public abstract fun <get-x> <D> (): D of <root>.IBase.<get-x>? declared in <root>.IBase' type=D of <root>.Test1.<get-x>? origin=null
<D>: <none>
<D>: D of <root>.Test1.<get-x>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<E of <root>.Test1> visibility:local [final]' type=<root>.IBase<E of <root>.Test1> origin=null
receiver: GET_VAR '<this>: <root>.Test1<E of <root>.Test1> declared in <root>.Test1.<get-x>' type=<root>.Test1<E of <root>.Test1> origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test1.<get-x>> declared in <root>.Test1.<get-x>' type=kotlin.collections.List<D of <root>.Test1.<get-x>> origin=null
@@ -104,7 +104,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.Test1.<set-x>?
BLOCK_BODY
CALL 'public abstract fun <set-x> <D> (<set-?>: D of <root>.IBase.<set-x>?): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<D>: <none>
<D>: D of <root>.Test1.<set-x>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<E of <root>.Test1> visibility:local [final]' type=<root>.IBase<E of <root>.Test1> origin=null
receiver: GET_VAR '<this>: <root>.Test1<E of <root>.Test1> declared in <root>.Test1.<set-x>' type=<root>.Test1<E of <root>.Test1> origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test1.<get-x>> declared in <root>.Test1.<set-x>' type=kotlin.collections.List<D of <root>.Test1.<get-x>> origin=null
@@ -141,7 +141,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:b index:1 type:B of <root>.Test2.foo
BLOCK_BODY
CALL 'public abstract fun foo <B> (a: A of <root>.IBase, b: B of <root>.IBase.foo): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<B>: <none>
<B>: B of <root>.Test2.foo
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<kotlin.String> visibility:local [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.foo' type=<root>.Test2 origin=null
a: GET_VAR 'a: kotlin.String declared in <root>.Test2.foo' type=kotlin.String origin=null
@@ -159,7 +159,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-id> <C> (): kotlin.collections.Map<kotlin.String, C of <root>.Test2.<get-id>>? declared in <root>.Test2'
CALL 'public abstract fun <get-id> <C> (): kotlin.collections.Map<A of <root>.IBase, C of <root>.IBase.<get-id>>? declared in <root>.IBase' type=kotlin.collections.Map<kotlin.String, C of <root>.Test2.<get-id>>? origin=null
<C>: <none>
<C>: C of <root>.Test2.<get-id>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<kotlin.String> visibility:local [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<get-id>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: C of <root>.Test2.<get-id> declared in <root>.Test2.<get-id>' type=C of <root>.Test2.<get-id> origin=null
@@ -176,7 +176,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-x> <D> (): D of <root>.Test2.<get-x>? declared in <root>.Test2'
CALL 'public abstract fun <get-x> <D> (): D of <root>.IBase.<get-x>? declared in <root>.IBase' type=D of <root>.Test2.<get-x>? origin=null
<D>: <none>
<D>: D of <root>.Test2.<get-x>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<kotlin.String> visibility:local [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<get-x>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test2.<get-x>> declared in <root>.Test2.<get-x>' type=kotlin.collections.List<D of <root>.Test2.<get-x>> origin=null
@@ -190,7 +190,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
VALUE_PARAMETER name:<set-?> index:0 type:D of <root>.Test2.<set-x>?
BLOCK_BODY
CALL 'public abstract fun <set-x> <D> (<set-?>: D of <root>.IBase.<set-x>?): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<D>: <none>
<D>: D of <root>.Test2.<set-x>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<kotlin.String> visibility:local [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<set-x>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test2.<get-x>> declared in <root>.Test2.<set-x>' type=kotlin.collections.List<D of <root>.Test2.<get-x>> origin=null
@@ -17,20 +17,20 @@ class Test1<E : Any?> : IBase<E> {
}
override fun <B : Any?> foo(a: E, b: B) {
<this>.#<$$delegate_0>.foo</* null */>(a = a, b = b)
<this>.#<$$delegate_0>.foo<B>(a = a, b = b)
}
override val <C : Any?> C.id: Map<E, C>?
override get(): Map<E, C>? {
return (<this>.#<$$delegate_0>, <this>).<get-id></* null */>()
return (<this>.#<$$delegate_0>, <this>).<get-id><C>()
}
override var <D : Any?> List<D>.x: D?
override get(): D? {
return (<this>.#<$$delegate_0>, <this>).<get-x></* null */>()
return (<this>.#<$$delegate_0>, <this>).<get-x><D>()
}
override set(<set-?>: D?) {
(<this>.#<$$delegate_0>, <this>).<set-x></* null */>(<set-?> = <set-?>)
(<this>.#<$$delegate_0>, <this>).<set-x><D>(<set-?> = <set-?>)
}
local /* final field */ val <$$delegate_0>: IBase<E> = i
@@ -45,20 +45,20 @@ class Test2 : IBase<String> {
}
override fun <B : Any?> foo(a: String, b: B) {
<this>.#<$$delegate_0>.foo</* null */>(a = a, b = b)
<this>.#<$$delegate_0>.foo<B>(a = a, b = b)
}
override val <C : Any?> C.id: Map<String, C>?
override get(): Map<String, C>? {
return (<this>.#<$$delegate_0>, <this>).<get-id></* null */>()
return (<this>.#<$$delegate_0>, <this>).<get-id><C>()
}
override var <D : Any?> List<D>.x: D?
override get(): D? {
return (<this>.#<$$delegate_0>, <this>).<get-x></* null */>()
return (<this>.#<$$delegate_0>, <this>).<get-x><D>()
}
override set(<set-?>: D?) {
(<this>.#<$$delegate_0>, <this>).<set-x></* null */>(<set-?> = <set-?>)
(<this>.#<$$delegate_0>, <this>).<set-x><D>(<set-?> = <set-?>)
}
local /* final field */ val <$$delegate_0>: IBase<String> = j
+1 -1
View File
@@ -14,7 +14,7 @@ FILE fqName:<root> fileName:/kt45934.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo <C> (): @[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.C.foo?>? declared in <root>.C'
CALL 'public abstract fun foo <C> (): @[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.I.foo?>? declared in <root>.I' type=@[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.C.foo?>? origin=null
<C>: <none>
<C>: C of <root>.C.foo
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.I visibility:local [final]' type=<root>.I origin=null
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.foo' type=<root>.C origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.I visibility:local [final]
@@ -43,7 +43,7 @@ FILE fqName:<root> fileName:/kt35550.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-id> <T> (): T of <root>.A.<get-id> declared in <root>.A'
CALL 'public open fun <get-id> <T> (): T of <root>.I.<get-id> declared in <root>.I' type=T of <root>.A.<get-id> origin=null
<T>: <none>
<T>: T of <root>.A.<get-id>
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.I visibility:local [final]' type=<root>.I origin=null
receiver: GET_VAR '<this>: <root>.A declared in <root>.A.<get-id>' type=<root>.A origin=null
$receiver: GET_VAR '<this>: T of <root>.A.<get-id> declared in <root>.A.<get-id>' type=T of <root>.A.<get-id> origin=null
@@ -15,7 +15,7 @@ class A : I {
override val <T : Any?> T.id: T
override get(): T {
return (<this>.#<$$delegate_0>, <this>).<get-id></* null */>()
return (<this>.#<$$delegate_0>, <this>).<get-id><T>()
}
local /* final field */ val <$$delegate_0>: I = i
@@ -54,7 +54,7 @@ FILE fqName:<root> fileName:/delegatedMembers.kt
VALUE_PARAMETER name:x index:1 type:X of <root>.Test.qux
BLOCK_BODY
CALL 'public abstract fun qux <X> (t: T of <root>.IBase, x: X of <root>.IBase.qux): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<X>: <none>
<X>: X of <root>.Test.qux
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase<TT of <root>.Test> visibility:local [final]' type=<root>.IBase<TT of <root>.Test> origin=null
receiver: GET_VAR '<this>: <root>.Test<TT of <root>.Test> declared in <root>.Test.qux' type=<root>.Test<TT of <root>.Test> origin=null
t: GET_VAR 't: TT of <root>.Test declared in <root>.Test.qux' type=TT of <root>.Test origin=null
@@ -19,7 +19,7 @@ class Test<TT : Any?> : IBase<TT> {
}
override fun <X : Any?> qux(t: TT, x: X) {
<this>.#<$$delegate_0>.qux</* null */>(t = t, x = x)
<this>.#<$$delegate_0>.qux<X>(t = t, x = x)
}
override val bar: Int