Files
kotlin-fork/compiler/fir/analysis-tests/testData/resolve/smartcasts/receivers/implicitReceivers.fir.txt
T
Tianyu Geng 765cad8448 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.
2021-09-17 01:59:06 +03:00

120 lines
4.3 KiB
Plaintext
Vendored

FILE: implicitReceivers.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final fun foo(): R|kotlin/Unit| {
}
}
public final class B : R|kotlin/Any| {
public constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final fun bar(): R|kotlin/Unit| {
}
}
public final fun <T> R|T|.with(block: R|T.() -> kotlin/Unit|): R|kotlin/Unit| {
}
public final fun R|kotlin/Any?|.test_1(): R|kotlin/Unit| {
when () {
(this@R|/test_1| is R|A|) -> {
this@R|/test_1|.R|/A.foo|()
this@R|/test_1|.R|/A.foo|()
}
else -> {
this@R|/test_1|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
}
}
this@R|/test_1|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
}
public final fun R|kotlin/Any?|.test_2(): R|kotlin/Unit| {
when () {
(this@R|/test_2| !is R|A|) -> {
this@R|/test_2|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
}
else -> {
this@R|/test_2|.R|/A.foo|()
this@R|/test_2|.R|/A.foo|()
}
}
this@R|/test_2|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
}
public final fun test_3(a: R|kotlin/Any|, b: R|kotlin/Any|, c: R|kotlin/Any|): R|kotlin/Unit| {
R|kotlin/with|<R|kotlin/Any|, R|kotlin/Unit|>(R|<local>/a|, <L> = wa@fun R|kotlin/Any|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
^ R|kotlin/with|<R|kotlin/Any|, R|kotlin/Unit|>(R|<local>/b|, <L> = wb@fun R|kotlin/Any|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
R|kotlin/with|<R|kotlin/Any|, R|kotlin/Unit|>(R|<local>/c|, <L> = wc@fun R|kotlin/Any|.<anonymous>(): R|kotlin/Unit| <inline=Inline, kind=EXACTLY_ONCE> {
(this@R|special/anonymous| as R|A|)
this@R|special/anonymous|.R|/A.foo|()
this@R|special/anonymous|.R|/A.foo|()
}
)
this@R|special/anonymous|.R|/A.foo|()
this@R|special/anonymous|.R|/A.foo|()
}
)
}
)
}
public final fun R|kotlin/Any?|.test_4(): R|kotlin/Unit| {
when () {
(this@R|/test_4| !is R|A|) -> {
this@R|/test_4|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
this@R|/test_4|.<Unresolved name: bar>#()
<Unresolved name: bar>#()
}
else -> {
when () {
(this@R|/test_4| !is R|B|) -> {
this@R|/test_4|.<Unresolved name: bar>#()
<Unresolved name: bar>#()
this@R|/test_4|.R|/A.foo|()
this@R|/test_4|.R|/A.foo|()
}
else -> {
this@R|/test_4|.R|/A.foo|()
this@R|/test_4|.R|/A.foo|()
this@R|/test_4|.R|/B.bar|()
this@R|/test_4|.R|/B.bar|()
}
}
}
}
this@R|/test_4|.<Unresolved name: foo>#()
<Unresolved name: foo>#()
this@R|/test_4|.<Unresolved name: bar>#()
<Unresolved name: bar>#()
}
public final fun R|kotlin/Any|.test_5(): R|kotlin/Int| {
^test_5 when () {
(this@R|/test_5| is R|kotlin/collections/List<*>|) -> {
this@R|/test_5|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
}
(this@R|/test_5| is R|kotlin/String|) -> {
this@R|/test_5|.R|kotlin/String.length|
}
else -> {
Int(0)
}
}
}
public final fun R|kotlin/Any|.test_6(): R|kotlin/Unit| {
(this@R|/test_6| as R|kotlin/collections/List<*>|)
this@R|/test_6|.R|SubstitutionOverride<kotlin/collections/List.size: R|kotlin/Int|>|
(this@R|/test_6| as R|kotlin/String|)
this@R|/test_6|.R|kotlin/String.length|
}