K2: Propagate explicit getter type to the property without initializer

In K1, we have the rules like:
- if there's explicit type of a property, then use it
- if there's an initializer, obtain its expression-type
- Otherwise, use getter's return type

The case when getter's type is implicit is handled at
FirDeclarationsResolveTransformer.transformProperty

^KT-56707 Fixed
This commit is contained in:
Denis.Zharkov
2023-02-20 16:53:33 +01:00
committed by Space Team
parent c09607c791
commit 3f052af517
10 changed files with 96 additions and 20 deletions
@@ -0,0 +1,19 @@
// FIR_IDENTICAL
// ISSUE: KT-56707
class Foo0 {
val child = 1
val allChildren
get(): Int = child + allChildren // Should not be TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM on `allChildren` reference
}
class Foo1 {
val child = 1
val allChildren
get() = child + 1
}
fun use() {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>Foo0().allChildren<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>Foo1().allChildren<!>
}
@@ -1,18 +0,0 @@
// !CHECK_TYPE
val x get(): String = foo()
val y get(): List<Int> = bar()
val z get(): List<Int> {
return bar()
}
val u get(): String = <!UNRESOLVED_REFERENCE!>field<!>
fun <E> foo(): E = null!!
fun <E> bar(): List<E> = null!!
fun baz() {
x checkType { _<String>() }
y checkType { _<List<Int>>() }
z checkType { _<List<Int>>() }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !CHECK_TYPE
val x get(): String = foo()
val y get(): List<Int> = bar()
@@ -0,0 +1,13 @@
// FIR_IDENTICAL
// WITH_STDLIB
// ISSUE: KT-56707
class Foo {
val children = mutableSetOf<Foo>()
val allChildren
get() : Set<Foo> = (children + children.flatMap { it.allChildren }).toSet() // Should not be TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM on `allChildren` reference
}
fun use() {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.Set<Foo>")!>Foo().allChildren<!>
}