[FE 1.0] Properly handle intersection types in check if cast possible or not

^KT-47685 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-07-12 10:43:53 +03:00
committed by teamcityserver
parent f0c4d06fc9
commit 47b0071560
8 changed files with 123 additions and 0 deletions
+29
View File
@@ -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
}