JVM, JVM IR: Don't optimize null-checks based on nullability information

Since Java interop allows us to circumvent the Kotlin type system we
cannot rely on nullability information.
This commit is contained in:
Steven Schäfer
2019-11-06 16:16:29 +01:00
committed by Alexander Udalov
parent de082543f1
commit b80e157381
6 changed files with 42 additions and 7 deletions
@@ -3871,12 +3871,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
Type type = expressionType(exp);
StackValue argument = pregeneratedExpr != null ? pregeneratedExpr : gen(exp);
if (kotlinType == null || TypeUtils.isNullableType(kotlinType)) {
if (kotlinType == null ||
!AsmUtil.isPrimitive(type) && (TypeUtils.isNullableType(kotlinType) || !InlineClassesUtilsKt.isInlineClassType(kotlinType))) {
return StackValue.compareWithNull(argument, (KtTokens.EQEQ == opToken || KtTokens.EQEQEQ == opToken) ? IFNONNULL : IFNULL);
} else {
// If exp has a non-nullable type, the comparison is vacuous.
// For inline classes we cannot necessarily compare with null at all.
// In this case the code below is necessary for correctness, not just an optimization.
// If exp is an unboxed inline class value the comparison is vacuous
return StackValue.operation(Type.BOOLEAN_TYPE, v -> {
argument.put(type, kotlinType, v);
AsmUtil.pop(v, type);