[FE 1.0] Properly handle intersection types in check if cast possible or not
^KT-47685 Fixed
This commit is contained in:
committed by
teamcityserver
parent
f0c4d06fc9
commit
47b0071560
@@ -0,0 +1,29 @@
|
||||
// KT-47685
|
||||
interface KtFunction {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
abstract class ASTDelegatePsiElement {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
class KtNamedFunction : ASTDelegatePsiElement(), KtFunction {
|
||||
fun baz() {}
|
||||
}
|
||||
class KtFunctionLiteral : ASTDelegatePsiElement(), KtFunction
|
||||
|
||||
fun test_1(namedFunction: KtNamedFunction, functionLiteral: KtFunctionLiteral, cond: Boolean) {
|
||||
val function = when (cond) {
|
||||
true -> namedFunction
|
||||
false -> functionLiteral
|
||||
}
|
||||
// approve that foo has type (ASTDelegatePsiElement & KtFunction)
|
||||
function.foo()
|
||||
function.bar()
|
||||
|
||||
if (function is KtNamedFunction) {
|
||||
function.baz()
|
||||
}
|
||||
|
||||
val myNamedFunction = function as KtNamedFunction
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// KT-47685
|
||||
interface KtFunction {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
abstract class ASTDelegatePsiElement {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
class KtNamedFunction : ASTDelegatePsiElement(), KtFunction {
|
||||
fun baz() {}
|
||||
}
|
||||
class KtFunctionLiteral : ASTDelegatePsiElement(), KtFunction
|
||||
|
||||
fun test_1(namedFunction: KtNamedFunction, functionLiteral: KtFunctionLiteral, cond: Boolean) {
|
||||
val function = when (cond) {
|
||||
true -> namedFunction
|
||||
false -> functionLiteral
|
||||
}
|
||||
// approve that foo has type (ASTDelegatePsiElement & KtFunction)
|
||||
function.foo()
|
||||
function.bar()
|
||||
|
||||
if (function is KtNamedFunction) {
|
||||
<!DEBUG_INFO_SMARTCAST!>function<!>.baz()
|
||||
}
|
||||
|
||||
val myNamedFunction = function as KtNamedFunction
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package
|
||||
|
||||
public fun test_1(/*0*/ namedFunction: KtNamedFunction, /*1*/ functionLiteral: KtFunctionLiteral, /*2*/ cond: kotlin.Boolean): kotlin.Unit
|
||||
|
||||
public abstract class ASTDelegatePsiElement {
|
||||
public constructor ASTDelegatePsiElement()
|
||||
public final fun bar(): kotlin.Unit
|
||||
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 interface KtFunction {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class KtFunctionLiteral : ASTDelegatePsiElement, KtFunction {
|
||||
public constructor KtFunctionLiteral()
|
||||
public final override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class KtNamedFunction : ASTDelegatePsiElement, KtFunction {
|
||||
public constructor KtNamedFunction()
|
||||
public final override /*1*/ /*fake_override*/ fun bar(): kotlin.Unit
|
||||
public final fun baz(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Reference in New Issue
Block a user