More precise type handling for equality #KT-2311 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
137a20e0ed
commit
5e9aa38950
@@ -0,0 +1,17 @@
|
||||
open class VeryBase
|
||||
|
||||
open class Base : VeryBase()
|
||||
|
||||
class Derived : Base() {
|
||||
fun original(): VeryBase = this
|
||||
}
|
||||
|
||||
class Another : Base()
|
||||
|
||||
fun foo(d: Derived, a: Another?): Base? {
|
||||
// d is compared with d.original(): VeryBase but should retain its own type
|
||||
if (d.original() != d) return null
|
||||
// ad should be of type Base, not VeryBase
|
||||
val ad = a ?: d
|
||||
return ad
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ d: Derived, /*1*/ a: Another?): Base?
|
||||
|
||||
public final class Another : Base {
|
||||
public constructor Another()
|
||||
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 Base : VeryBase {
|
||||
public constructor Base()
|
||||
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 Derived : Base {
|
||||
public constructor Derived()
|
||||
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 final fun original(): VeryBase
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class VeryBase {
|
||||
public constructor VeryBase()
|
||||
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 @@
|
||||
fun foo(): Int {
|
||||
val x: Any? = null
|
||||
val y = 2
|
||||
if (x == y) {
|
||||
return <!DEBUG_INFO_SMARTCAST!>x<!> + y
|
||||
}
|
||||
return y
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Int
|
||||
Reference in New Issue
Block a user