FIR checker: substitute type parameters in dispatch receiver type

Consider the following code:

```
fun test(a: List<String>) {
  a.first()
}
```

The dispatch receiver type of `first` in this case is `List<T>` before
this change. After this change, it's `List<String>`.

In addition, this change also replace the dispatch receiver type with
the more specific type if available. For example, consider the following

```
class MyList: ArrayList<String>()

fun test(a: MyList) {
  a.get(0)
}
```
The dispatch receiver type of `get` is `MyList`, instead of
`ArrayList<String>`. That is, a fake override is created in this case.
This commit is contained in:
Tianyu Geng
2021-08-06 14:56:37 -07:00
committed by teamcityserver
parent c047adbaec
commit 765cad8448
61 changed files with 342 additions and 145 deletions
+1 -1
View File
@@ -575,7 +575,7 @@ FILE fqName:<root> fileName:/ArrayMap.kt
arg1: CALL 'public final fun <get-size> (): kotlin.Int declared in kotlin.Array' type=kotlin.Int origin=GET_PROPERTY
$this: CALL 'private final fun <get-data> (): kotlin.Array<kotlin.Any?> declared in <root>.ArrayMapImpl' type=kotlin.Array<kotlin.Any?> origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.ArrayMapImpl<T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator' type=<root>.ArrayMapImpl<T of <root>.ArrayMapImpl> origin=null
then: CALL 'protected final fun done (): kotlin.Unit declared in kotlin.collections.AbstractIterator' type=kotlin.Unit origin=null
then: CALL 'protected final fun done (): kotlin.Unit [fake_override] declared in <root>.ArrayMapImpl.iterator.<no name provided>' type=kotlin.Unit origin=null
$this: GET_VAR '<this>: <root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> declared in <root>.ArrayMapImpl.iterator.<no name provided>.computeNext' type=<root>.ArrayMapImpl.iterator.<no name provided><T of <root>.ArrayMapImpl> origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
@@ -31,10 +31,9 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
FUN DELEGATED_MEMBER name:clear visibility:public modality:OPEN <> ($this:<root>.Impl) returnType:kotlin.Unit
overridden:
public abstract fun clear (): kotlin.Unit [fake_override] declared in <root>.Foo.A
public abstract fun clear (): kotlin.Unit [fake_override] declared in <root>.Foo.B
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
BLOCK_BODY
CALL 'public abstract fun clear (): kotlin.Unit declared in kotlin.collections.MutableSet' type=kotlin.Unit origin=null
CALL 'public abstract fun clear (): kotlin.Unit [fake_override] declared in <root>.Foo.B' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.Foo.B visibility:local [final]' type=<root>.Foo.B origin=null
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.clear' type=<root>.Impl origin=null
FUN DELEGATED_MEMBER name:iterator visibility:public modality:OPEN <> ($this:<root>.Impl) returnType:kotlin.collections.MutableIterator<@[FlexibleNullability] kotlin.String?> [operator]
@@ -104,26 +103,23 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
FUN DELEGATED_MEMBER name:isEmpty visibility:public modality:OPEN <> ($this:<root>.Impl) returnType:kotlin.Boolean
overridden:
public abstract fun isEmpty (): kotlin.Boolean [fake_override] declared in <root>.Foo.A
public abstract fun isEmpty (): kotlin.Boolean [fake_override] declared in <root>.Foo.B
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun isEmpty (): kotlin.Boolean declared in <root>.Impl'
CALL 'public abstract fun isEmpty (): kotlin.Boolean declared in kotlin.collections.Set' type=kotlin.Boolean origin=null
CALL 'public abstract fun isEmpty (): kotlin.Boolean [fake_override] declared in <root>.Foo.B' type=kotlin.Boolean origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.Foo.B visibility:local [final]' type=<root>.Foo.B origin=null
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.isEmpty' type=<root>.Impl origin=null
PROPERTY DELEGATED_MEMBER name:size visibility:public modality:OPEN [val]
overridden:
public abstract size: kotlin.Int [fake_override,val]
public abstract size: kotlin.Int [fake_override,val]
FUN DELEGATED_MEMBER name:<get-size> visibility:public modality:OPEN <> ($this:<root>.Impl) returnType:kotlin.Int
correspondingProperty: PROPERTY DELEGATED_MEMBER name:size visibility:public modality:OPEN [val]
overridden:
public abstract fun <get-size> (): kotlin.Int [fake_override] declared in <root>.Foo.A
public abstract fun <get-size> (): kotlin.Int [fake_override] declared in <root>.Foo.B
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun <get-size> (): kotlin.Int declared in <root>.Impl'
CALL 'public abstract fun <get-size> (): kotlin.Int declared in kotlin.collections.Set' type=kotlin.Int origin=null
CALL 'public abstract fun <get-size> (): kotlin.Int [fake_override] declared in <root>.Foo.B' type=kotlin.Int origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.Foo.B visibility:local [final]' type=<root>.Foo.B origin=null
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.<get-size>' type=<root>.Impl origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.Foo.B visibility:local [final]
+7 -8
View File
@@ -201,12 +201,11 @@ FILE fqName:<root> fileName:/MultiList.kt
public open fun contains (p0: @[FlexibleNullability] E of java.util.ArrayList?): kotlin.Boolean [operator] declared in java.util.ArrayList
$this: VALUE_PARAMETER name:<this> type:java.util.ArrayList<E of java.util.ArrayList>
VALUE_PARAMETER name:p0 index:0 type:@[FlexibleNullability] <root>.Some<T of <root>.SomeList>?
FUN FAKE_OVERRIDE name:containsAll visibility:public modality:OPEN <> ($this:kotlin.collections.List<E of kotlin.collections.List>, elements:kotlin.collections.Collection<<root>.Some<T of <root>.SomeList>>) returnType:kotlin.Boolean [fake_override]
FUN FAKE_OVERRIDE name:containsAll visibility:public modality:OPEN <> ($this:java.util.AbstractCollection<E of java.util.AbstractCollection>, p0:kotlin.collections.Collection<@[FlexibleNullability] <root>.Some<T of <root>.SomeList>?>) returnType:kotlin.Boolean [fake_override]
overridden:
public abstract fun containsAll (elements: kotlin.collections.Collection<<root>.Some<T of <root>.MyList>>): kotlin.Boolean [fake_override] declared in <root>.MyList
public open fun containsAll (p0: kotlin.collections.Collection<@[FlexibleNullability] E of java.util.ArrayList?>): kotlin.Boolean [fake_override] declared in java.util.ArrayList
$this: VALUE_PARAMETER name:<this> type:kotlin.collections.List<E of kotlin.collections.List>
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<<root>.Some<T of <root>.SomeList>>
$this: VALUE_PARAMETER name:<this> type:java.util.AbstractCollection<E of java.util.AbstractCollection>
VALUE_PARAMETER name:p0 index:0 type:kotlin.collections.Collection<@[FlexibleNullability] <root>.Some<T of <root>.SomeList>?>
FUN FAKE_OVERRIDE name:get visibility:public modality:OPEN <> ($this:java.util.ArrayList<E of java.util.ArrayList>, p0:kotlin.Int) returnType:@[FlexibleNullability] <root>.Some<T of <root>.SomeList>? [fake_override,operator]
overridden:
public open fun get (p0: kotlin.Int): @[FlexibleNullability] E of java.util.ArrayList? [operator] declared in java.util.ArrayList
@@ -396,11 +395,11 @@ FILE fqName:<root> fileName:/MultiList.kt
public open fun contains (p0: @[FlexibleNullability] <root>.Some<T of <root>.SomeList>?): kotlin.Boolean [fake_override,operator] declared in <root>.SomeList
$this: VALUE_PARAMETER name:<this> type:java.util.ArrayList<E of java.util.ArrayList>
VALUE_PARAMETER name:p0 index:0 type:@[FlexibleNullability] <root>.Some<kotlin.String>?
FUN FAKE_OVERRIDE name:containsAll visibility:public modality:OPEN <> ($this:kotlin.collections.List<E of kotlin.collections.List>, elements:kotlin.collections.Collection<<root>.Some<kotlin.String>>) returnType:kotlin.Boolean [fake_override]
FUN FAKE_OVERRIDE name:containsAll visibility:public modality:OPEN <> ($this:java.util.AbstractCollection<E of java.util.AbstractCollection>, p0:kotlin.collections.Collection<@[FlexibleNullability] <root>.Some<kotlin.String>?>) returnType:kotlin.Boolean [fake_override]
overridden:
public open fun containsAll (elements: kotlin.collections.Collection<<root>.Some<T of <root>.SomeList>>): kotlin.Boolean [fake_override] declared in <root>.SomeList
$this: VALUE_PARAMETER name:<this> type:kotlin.collections.List<E of kotlin.collections.List>
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<<root>.Some<kotlin.String>>
public open fun containsAll (p0: kotlin.collections.Collection<@[FlexibleNullability] <root>.Some<T of <root>.SomeList>?>): kotlin.Boolean [fake_override] declared in <root>.SomeList
$this: VALUE_PARAMETER name:<this> type:java.util.AbstractCollection<E of java.util.AbstractCollection>
VALUE_PARAMETER name:p0 index:0 type:kotlin.collections.Collection<@[FlexibleNullability] <root>.Some<kotlin.String>?>
FUN FAKE_OVERRIDE name:get visibility:public modality:OPEN <> ($this:java.util.ArrayList<E of java.util.ArrayList>, p0:kotlin.Int) returnType:@[FlexibleNullability] <root>.Some<kotlin.String>? [fake_override,operator]
overridden:
public open fun get (p0: kotlin.Int): @[FlexibleNullability] <root>.Some<T of <root>.SomeList>? [fake_override,operator] declared in <root>.SomeList