From aea5e3ffbcb698b166c1c8759d6b673c2a24b0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Wed, 22 Jan 2020 11:38:20 +0100 Subject: [PATCH] JVM IR: Remove type substitutions from ExpressionCodegen Instead, determine whether the return type of a call is Nothing, by looking at the type of the call expression. --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 7 +++---- compiler/testData/codegen/box/bridges/kt1959.kt | 1 - .../codegen/box/bridges/overrideAbstractProperty.kt | 1 - .../codegen/box/elvis/kt6694ExactAnnotationForElvis.kt | 1 - .../functionExpressionWithThisReference.kt | 2 -- .../javaInterop/notNullAssertions/nullableTypeParameter.kt | 1 - ...henNullableTypeParameterReplacedWithIntersectionType.kt | 1 - .../codegen/box/statics/inheritedPropertyInObject.kt | 1 - 8 files changed, 3 insertions(+), 12 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index 26fb205f56b..0c62102a350 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -453,9 +453,8 @@ class ExpressionCodegen( addInlineMarker(mv, isStartNotEnd = false) } - val returnType = callee.returnType return when { - returnType.substitute(expression.typeSubstitutionMap).isNothing() -> { + expression.type.isNothing() -> { mv.aconst(null) mv.athrow() immaterialUnitValue @@ -467,9 +466,9 @@ class ExpressionCodegen( immaterialUnitValue expression.type.isUnit() -> // NewInference allows casting `() -> T` to `() -> Unit`. A CHECKCAST here will fail. - MaterialValue(this, callable.asmMethod.returnType, returnType).discard().coerce(expression.type) + MaterialValue(this, callable.asmMethod.returnType, callee.returnType).discard().coerce(expression.type) else -> - MaterialValue(this, callable.asmMethod.returnType, returnType).coerce(expression.type) + MaterialValue(this, callable.asmMethod.returnType, callee.returnType).coerce(expression.type) } } diff --git a/compiler/testData/codegen/box/bridges/kt1959.kt b/compiler/testData/codegen/box/bridges/kt1959.kt index c3ee33f0936..e820d707615 100644 --- a/compiler/testData/codegen/box/bridges/kt1959.kt +++ b/compiler/testData/codegen/box/bridges/kt1959.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A { open fun f(args : Array) {} } diff --git a/compiler/testData/codegen/box/bridges/overrideAbstractProperty.kt b/compiler/testData/codegen/box/bridges/overrideAbstractProperty.kt index 0240784b692..ec01cfced5c 100644 --- a/compiler/testData/codegen/box/bridges/overrideAbstractProperty.kt +++ b/compiler/testData/codegen/box/bridges/overrideAbstractProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR public abstract class AbstractClass { public abstract val some: T } diff --git a/compiler/testData/codegen/box/elvis/kt6694ExactAnnotationForElvis.kt b/compiler/testData/codegen/box/elvis/kt6694ExactAnnotationForElvis.kt index 52a32396369..af26c6e87f2 100644 --- a/compiler/testData/codegen/box/elvis/kt6694ExactAnnotationForElvis.kt +++ b/compiler/testData/codegen/box/elvis/kt6694ExactAnnotationForElvis.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface PsiElement { fun findChildByType(i: Int): T? = if (i == 42) JetOperationReferenceExpression() as T else throw Exception() diff --git a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt index ae362fd65f9..eca7e8a8c2e 100644 --- a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt +++ b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt @@ -1,6 +1,4 @@ // IGNORE_BACKEND_FIR: JVM_IR -// IGNORE_BACKEND: JVM_IR -// For JVM_IR, NewInference is needed because of KT-26531. See functionExpressionWithThisReferenceNI.kt fun Int.thisRef1() = fun () = this fun Int.thisRef2() = fun (): Int {return this} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt index f002766378f..7dd8f055f7a 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/nullableTypeParameter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM interface I { fun f(x: T?) = x ?: "OK" diff --git a/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt b/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt index c2c7f92a074..925ff26edd9 100644 --- a/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt +++ b/compiler/testData/codegen/box/regressions/noAssertionsWhenNullableTypeParameterReplacedWithIntersectionType.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference -// IGNORE_BACKEND_FIR: JVM_IR class Recursive> : Generic>, MainSupertype open class Simple : Generic, MainSupertype diff --git a/compiler/testData/codegen/box/statics/inheritedPropertyInObject.kt b/compiler/testData/codegen/box/statics/inheritedPropertyInObject.kt index db69f0321bb..4d00f209f61 100644 --- a/compiler/testData/codegen/box/statics/inheritedPropertyInObject.kt +++ b/compiler/testData/codegen/box/statics/inheritedPropertyInObject.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class Bar(val prop: String) object Foo : Bar("OK") {