Implicit nothing / intersection types are now checked also for member functions #KT-11666 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-03-30 13:10:51 +03:00
committed by Mikhail Glukhikh
parent 0ea3b4ade4
commit 4c03aaabd4
13 changed files with 49 additions and 16 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import kotlin.reflect.KProperty
class NotImplemented<T>(){
operator fun getValue(thisRef: Any?, prop: KProperty<*>): T = notImplemented()
operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: T) = notImplemented()
operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: T): Nothing = notImplemented()
}
fun notImplemented() : Nothing = notImplemented()
@@ -27,7 +27,7 @@ class C {
object Delegate {
operator fun getValue(x: C, p: KProperty<*>) = throw AssertionError()
operator fun getValue(x: C, p: KProperty<*>): Nothing = throw AssertionError()
operator fun setValue(x: C, p: KProperty<*>, value: Int) = throw AssertionError()
operator fun setValue(x: C, p: KProperty<*>, value: Int): Nothing = throw AssertionError()
}
@@ -14,6 +14,8 @@ class My(b: B) {
val <!IMPLICIT_INTERSECTION_TYPE!>x<!> = if (b is A && b is C) b else null
// Ok: given explicitly
val y: C? = if (b is A && b is C) <!DEBUG_INFO_SMARTCAST!>b<!> else null
// Error!
fun <!IMPLICIT_INTERSECTION_TYPE!>foo<!>(b: B) = if (b is A && b is C) b else null
}
fun bar(b: B): String {
@@ -28,6 +28,7 @@ public final class My {
public final val x: {C & A & B}?
public final val y: C?
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(/*0*/ b: B): {C & A & B}?
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
+18
View File
@@ -16,3 +16,21 @@ fun check() {
// Unreachable / unused, but not implicit Nothing
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>x<!> =<!> null!!
}
class Klass {
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>bar<!>() = null!!
val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y<!> = null!!
init {
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>local<!>() = bar()
// Should be unreachable: see KT-5311
val z = null!!
}
fun foo() {
fun <!IMPLICIT_NOTHING_RETURN_TYPE!>local<!>() = bar()
<!UNREACHABLE_CODE!>val <!UNUSED_VARIABLE!>x<!> =<!> y
}
}
+10
View File
@@ -7,3 +7,13 @@ public fun baz(): kotlin.Nothing
public fun check(): kotlin.Unit
public fun foo(): kotlin.Nothing
public fun gav(): kotlin.Any
public final class Klass {
public constructor Klass()
public final val y: kotlin.Nothing
public final fun bar(): kotlin.Nothing
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
}
@@ -6,6 +6,6 @@ annotation class Anno
class Class {
@Anno val x: Int by object {
operator fun getValue(thiz: Class, data: KProperty<*>) = null!!
operator fun getValue(thiz: Class, data: KProperty<*>): Nothing = null!!
}
}
@@ -8,5 +8,5 @@ import kotlin.reflect.KProperty
annotation class Anno
@Anno val x: Int by object {
operator fun getValue(thiz: Any?, data: KProperty<*>) = null!!
operator fun getValue(thiz: Any?, data: KProperty<*>): Nothing = null!!
}