FIR: Support proper implicit return type computation for local classes

This commit is contained in:
Denis Zharkov
2020-03-20 16:43:16 +03:00
parent 94193c91a0
commit cdd7e41891
14 changed files with 377 additions and 38 deletions
@@ -0,0 +1,16 @@
private val x = object {
fun foo(x: Int) = /* here we have not computed return type for "bar" */bar(x)
fun bar(y: Int) = this.hashCode() + y > 0
val w get() = z
val z get() = this.hashCode() == 0
}
fun useBoolean(b: Boolean) {}
fun main() {
useBoolean(x.foo(1))
useBoolean(x.bar(2))
useBoolean(x.w)
useBoolean(x.z)
}
@@ -0,0 +1,35 @@
FILE: implicitInAnonymous.kt
private final val x: R|anonymous| = object : R|kotlin/Any| {
private constructor(): R|anonymous| {
super<R|kotlin/Any|>()
}
public final fun foo(x: R|kotlin/Int|): R|kotlin/Boolean| {
^foo this@R|/anonymous|.R|/anonymous.bar|(R|<local>/x|)
}
public final fun bar(y: R|kotlin/Int|): R|kotlin/Boolean| {
^bar CMP(>, this@R|/anonymous|.R|kotlin/Any.hashCode|().R|kotlin/Int.plus|(R|<local>/y|).R|kotlin/Int.compareTo|(Int(0)))
}
public final val w: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ this@R|/anonymous|.R|/anonymous.z|
}
public final val z: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ ==(this@R|/anonymous|.R|kotlin/Any.hashCode|(), Int(0))
}
}
private get(): R|anonymous|
public final fun useBoolean(b: R|kotlin/Boolean|): R|kotlin/Unit| {
}
public final fun main(): R|kotlin/Unit| {
R|/useBoolean|(R|/x|.R|/anonymous.foo|(Int(1)))
R|/useBoolean|(R|/x|.R|/anonymous.bar|(Int(2)))
R|/useBoolean|(R|/x|.R|/anonymous.w|)
R|/useBoolean|(R|/x|.R|/anonymous.z|)
}
@@ -0,0 +1,37 @@
fun useBoolean(b: Boolean) {}
fun main() {
class A {
fun foo(x: Int) = bar(x)
fun bar(y: Int) = this.hashCode() + y > 0
val w get() = z
val z get() = this.hashCode() == 0
}
val a = A()
useBoolean(a.foo(1))
useBoolean(a.bar(1))
useBoolean(a.w)
useBoolean(a.z)
class B {
fun foo(x: Int) = inner.w
fun bar(y: Int) = this.hashCode() + y > 0
val inner = Inner()
inner class Inner {
val w get() = z
val z get() = bar(1)
}
}
val b = B()
useBoolean(b.foo(1))
useBoolean(b.bar(1))
useBoolean(b.inner.w)
useBoolean(b.inner.z)
}
@@ -0,0 +1,75 @@
FILE: implicitInLocalClasses.kt
public final fun useBoolean(b: R|kotlin/Boolean|): R|kotlin/Unit| {
}
public final fun main(): R|kotlin/Unit| {
local final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final fun foo(x: R|kotlin/Int|): R|kotlin/Boolean| {
^foo this@R|/A|.R|/A.bar|(R|<local>/x|)
}
public final fun bar(y: R|kotlin/Int|): R|kotlin/Boolean| {
^bar CMP(>, this@R|/A|.R|kotlin/Any.hashCode|().R|kotlin/Int.plus|(R|<local>/y|).R|kotlin/Int.compareTo|(Int(0)))
}
public final val w: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ this@R|/A|.R|/A.z|
}
public final val z: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ ==(this@R|/A|.R|kotlin/Any.hashCode|(), Int(0))
}
}
lval a: R|A| = R|/A.A|()
R|/useBoolean|(R|<local>/a|.R|/A.foo|(Int(1)))
R|/useBoolean|(R|<local>/a|.R|/A.bar|(Int(1)))
R|/useBoolean|(R|<local>/a|.R|/A.w|)
R|/useBoolean|(R|<local>/a|.R|/A.z|)
local final class B : R|kotlin/Any| {
public constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final fun foo(x: R|kotlin/Int|): R|kotlin/Boolean| {
^foo this@R|/B|.R|/B.inner|.R|/B.Inner.w|
}
public final fun bar(y: R|kotlin/Int|): R|kotlin/Boolean| {
^bar CMP(>, this@R|/B|.R|kotlin/Any.hashCode|().R|kotlin/Int.plus|(R|<local>/y|).R|kotlin/Int.compareTo|(Int(0)))
}
public final val inner: R|B.Inner| = this@R|/B|.R|/B.Inner.Inner|()
public get(): R|B.Inner|
local final inner class Inner : R|kotlin/Any| {
public constructor(): R|B.Inner| {
super<R|kotlin/Any|>()
}
public final val w: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ this@R|/B.Inner|.R|/B.Inner.z|
}
public final val z: R|kotlin/Boolean|
public get(): R|kotlin/Boolean| {
^ this@R|/B|.R|/B.bar|(Int(1))
}
}
}
lval b: R|B| = R|/B.B|()
R|/useBoolean|(R|<local>/b|.R|/B.foo|(Int(1)))
R|/useBoolean|(R|<local>/b|.R|/B.bar|(Int(1)))
R|/useBoolean|(R|<local>/b|.R|/B.inner|.R|/B.Inner.w|)
R|/useBoolean|(R|<local>/b|.R|/B.inner|.R|/B.Inner.z|)
}