From 687698da9a9a0fc193d89c2a131d52576449af71 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 9 Aug 2016 16:48:11 +0300 Subject: [PATCH] Do not report USELESS_CAST when casting null to nullable (special case) --- .../kotlin/types/expressions/BasicExpressionTypingVisitor.java | 1 + compiler/testData/diagnostics/tests/cast/NullableToNullable.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index ab5db78f9f1..74c323bbde7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -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)) { diff --git a/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt b/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt index 67a064bd39f..cd76ae9a3c2 100644 --- a/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt +++ b/compiler/testData/diagnostics/tests/cast/NullableToNullable.kt @@ -1,5 +1,5 @@ // From KT-13324: always succeeds -val x = null as String? +val x = null as String? // From KT-260: sometimes succeeds fun foo(a: String?): Int? { val c = a as? Int?