Allow inferring property type from its getter

#KT-550 Fixed
This commit is contained in:
Denis Zharkov
2016-11-14 14:17:39 +03:00
parent 51a5bf9f7e
commit 6fca46a452
32 changed files with 460 additions and 38 deletions
@@ -1,3 +0,0 @@
class A {
<!PROPERTY_WITH_NO_TYPE_NO_INITIALIZER!>val a<!> get() = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>
}
@@ -24,7 +24,7 @@ class Foo {
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>public val <!EXPOSED_PROPERTY_TYPE!>publicProperty<!><!> = object : MyClass(), MyTrait {}
<!PROPERTY_WITH_NO_TYPE_NO_INITIALIZER!>val propertyWithGetter<!>
val <!EXPOSED_PROPERTY_TYPE!>propertyWithGetter<!>
<!AMBIGUOUS_ANONYMOUS_TYPE_INFERRED!>get()<!> = object: MyClass(), MyTrait {}
@@ -117,4 +117,4 @@ fun fooPackage() {
fun fooPackageLocal() = object : MyClass(), MyTrait {}
fooPackageLocal().f1()
fooPackageLocal().f2()
}
}
@@ -16,7 +16,7 @@ public final class Foo {
internal final val internal2Property: Foo.internal2Property.<no name provided>
public final val internalProperty: Foo.internalProperty.<no name provided>
private final val privateProperty: Foo.privateProperty.<no name provided>
public final val propertyWithGetter: [ERROR : No type, no body]
public final val propertyWithGetter: Foo.<get-propertyWithGetter>.<no name provided>
protected final val protectedProperty: Foo.protectedProperty.<no name provided>
public final val publicProperty: Foo.publicProperty.<no name provided>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -0,0 +1,3 @@
<!PROPERTY_WITH_NO_TYPE_NO_INITIALIZER!>val x<!> get() {
return 1
}
@@ -0,0 +1,3 @@
package
public val x: [ERROR : No type, no body]
@@ -0,0 +1,5 @@
val x get() = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>()
val y get() = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>()
fun <E> foo(): E = null!!
fun <E> bar(): List<E> = null!!
@@ -0,0 +1,6 @@
package
public val x: [ERROR : Error function type]
public val y: [ERROR : Error function type]
public fun </*0*/ E> bar(): kotlin.collections.List<E>
public fun </*0*/ E> foo(): E
@@ -0,0 +1,18 @@
// !CHECK_TYPE
val x get(): String = foo()
val y get(): List<Int> = bar()
val z get(): List<Int> {
return bar()
}
<!MUST_BE_INITIALIZED!>val u<!> get(): String = 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>>() }
}
@@ -0,0 +1,9 @@
package
public val u: kotlin.String
public val x: kotlin.String
public val y: kotlin.collections.List<kotlin.Int>
public val z: kotlin.collections.List<kotlin.Int>
public fun </*0*/ E> bar(): kotlin.collections.List<E>
public fun baz(): kotlin.Unit
public fun </*0*/ E> foo(): E
@@ -0,0 +1,24 @@
// !CHECK_TYPE
class A {
val x get() = 1
val y get() = id(1)
val y2 get() = id(id(2))
val z get() = l("")
val z2 get() = l(id(l("")))
val <T> T.u get() = id(this)
}
fun <E> id(x: E) = x
fun <E> l(<!UNUSED_PARAMETER!>x<!>: E): List<E> = null!!
fun foo(a: A) {
a.x checkType { _<Int>() }
a.y checkType { _<Int>() }
a.y2 checkType { _<Int>() }
a.z checkType { _<List<String>>() }
a.z2 checkType { _<List<List<String>>>() }
with(a) {
1.u checkType { _<Int>() }
}
}
@@ -0,0 +1,18 @@
package
public fun foo(/*0*/ a: A): kotlin.Unit
public fun </*0*/ E> id(/*0*/ x: E): E
public fun </*0*/ E> l(/*0*/ x: E): kotlin.collections.List<E>
public final class A {
public constructor A()
public final val x: kotlin.Int
public final val y: kotlin.Int
public final val y2: kotlin.Int
public final val z: kotlin.collections.List<kotlin.String>
public final val z2: kotlin.collections.List<kotlin.collections.List<kotlin.String>>
public final val </*0*/ T> T.u: T
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,8 @@
// !CHECK_TYPE
val x get() = null
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y<!> get() = null!!
fun foo() {
<!DEBUG_INFO_CONSTANT!>x<!> checkType { _<Nothing?>() }
y <!UNREACHABLE_CODE!>checkType { _<Nothing>() }<!>
}
@@ -0,0 +1,5 @@
package
public val x: kotlin.Nothing?
public val y: kotlin.Nothing
public fun foo(): kotlin.Unit
@@ -0,0 +1,35 @@
// !CHECK_TYPE
object Outer {
private var x
get() = object : CharSequence {
override val length: Int
get() = 0
override fun get(index: Int): Char {
checkSubtype<CharSequence>(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>x<!>)
return ' '
}
override fun subSequence(startIndex: Int, endIndex: Int) = ""
fun bar() {
}
}
set(q) {
checkSubtype<CharSequence>(x)
y = q
x = q
}
private var y = <!DEBUG_INFO_LEAKING_THIS!>x<!>
fun foo() {
x = y
checkSubtype<CharSequence>(x)
checkSubtype<CharSequence>(y)
x.bar()
y.bar()
}
}
@@ -1,9 +1,11 @@
package
public final class A {
public constructor A()
public final val a: [ERROR : No type, no body]
public object Outer {
private constructor Outer()
private final var x: Outer.<get-x>.<no name provided>
private final var y: Outer.<get-x>.<no name provided>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,41 @@
// !CHECK_TYPE
interface A {
val x: Int
val z: Comparable<*>
}
open class B {
open var y = ""
open val z: CharSequence = ""
}
class C : B(), A {
override val x
get() = 1
override var y
get() = super.y
set(value) {
value checkType { _<String>() }
}
override var z
get() = ""
set(value) {
value checkType { _<String>() }
}
}
fun foo(c: C) {
c.x checkType { _<Int>() }
c.y checkType { _<String>() }
c.z checkType { _<String>() }
c.y = ""
c.y = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
c.z = ""
c.z = <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
}
@@ -0,0 +1,30 @@
package
public fun foo(/*0*/ c: C): kotlin.Unit
public interface A {
public abstract val x: kotlin.Int
public abstract val z: kotlin.Comparable<*>
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class B {
public constructor B()
public open var y: kotlin.String
public open val z: kotlin.CharSequence
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class C : B, A {
public constructor C()
public open override /*1*/ val x: kotlin.Int
public open override /*1*/ var y: kotlin.String
public open override /*2*/ var z: kotlin.String
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,18 @@
// !CHECK_TYPE
val x get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>x<!>
class A {
val y get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>y<!>
val a get() = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>b<!>
val b get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>a<!>
val z1 get() = id(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>z1<!>)
val z2 get() = l(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>z2<!>)
val u get() = <!UNRESOLVED_REFERENCE!>field<!>
}
fun <E> id(x: E) = x
fun <E> l(<!UNUSED_PARAMETER!>x<!>: E): List<E> = null!!
@@ -0,0 +1,18 @@
package
public val x: [ERROR : Error function type]
public fun </*0*/ E> id(/*0*/ x: E): E
public fun </*0*/ E> l(/*0*/ x: E): kotlin.collections.List<E>
public final class A {
public constructor A()
public final val a: [ERROR : Error function type]
public final val b: [ERROR : Error function type]
public final val u: [ERROR : Error function type]
public final val y: [ERROR : Error function type]
public final val z1: [ERROR : Error function type]
public final val z2: [ERROR : Error function type]
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,21 @@
// !CHECK_TYPE
val x get() = 1
val y get() = id(1)
val y2 get() = id(id(2))
val z get() = l("")
val z2 get() = l(id(l("")))
val <T> T.u get() = id(this)
fun <E> id(x: E) = x
fun <E> l(<!UNUSED_PARAMETER!>x<!>: E): List<E> = null!!
fun foo() {
x checkType { _<Int>() }
y checkType { _<Int>() }
y2 checkType { _<Int>() }
z checkType { _<List<String>>() }
z2 checkType { _<List<List<String>>>() }
1.u checkType { _<Int>() }
}
@@ -0,0 +1,11 @@
package
public val x: kotlin.Int
public val y: kotlin.Int
public val y2: kotlin.Int
public val z: kotlin.collections.List<kotlin.String>
public val z2: kotlin.collections.List<kotlin.collections.List<kotlin.String>>
public val </*0*/ T> T.u: T
public fun foo(): kotlin.Unit
public fun </*0*/ E> id(/*0*/ x: E): E
public fun </*0*/ E> l(/*0*/ x: E): kotlin.collections.List<E>
@@ -0,0 +1,21 @@
// !CHECK_TYPE
var x
get() = 1
set(q) {
q checkType { _<Int>() }
}
<!MUST_BE_INITIALIZED!>var noSetter<!>
get() = 1
fun foo() {
x checkType { _<Int>() }
noSetter checkType { _<Int>() }
x = 1
x = <!TYPE_MISMATCH!>""<!>
noSetter = 2
noSetter = <!TYPE_MISMATCH!>""<!>
}
@@ -0,0 +1,5 @@
package
public var noSetter: kotlin.Int
public var x: kotlin.Int
public fun foo(): kotlin.Unit