Do not report USELESS_CAST when casting null to nullable (special case)
This commit is contained in:
+1
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user