Do not report USELESS_CAST when casting null to nullable (special case)

This commit is contained in:
Mikhail Glukhikh
2016-08-09 16:48:11 +03:00
parent 8d537d294a
commit 687698da9a
2 changed files with 2 additions and 1 deletions
@@ -331,6 +331,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
private static boolean isUpcast(KotlinType candidateType, KotlinType targetType, KotlinTypeChecker typeChecker) {
if (KotlinBuiltIns.isNullableNothing(candidateType)) return false;
if (!typeChecker.isSubtypeOf(candidateType, targetType)) return false;
if (isFunctionType(candidateType) && isFunctionType(targetType)) {
@@ -1,5 +1,5 @@
// From KT-13324: always succeeds
val x = null <!USELESS_CAST!>as String?<!>
val x = null as String?
// From KT-260: sometimes succeeds
fun foo(a: String?): Int? {
val c = a as? Int?