From 4ff2825de0bd0a2a25ac1793317652b5370fca59 Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Thu, 21 Mar 2019 16:46:07 -0700 Subject: [PATCH] Fix an assertion for type parameters --- .../org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt | 8 +++++--- .../box/ieee754/equalsNaN_properIeeeComparisons.kt | 1 - .../src/org/jetbrains/kotlin/types/TypeUtils.kt | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt index a58bb6d52bf..211da1673fd 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/Equals.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberOrNullableType +import org.jetbrains.kotlin.types.typeUtil.upperBoundedByPrimitiveNumberOrNullableType import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter @@ -97,10 +98,12 @@ class Ieee754Equals(val operandType: Type) : IntrinsicMethod() { } val arg0Type = expression.getValueArgument(0)!!.type.toKotlinType() - if (!arg0Type.isPrimitiveNumberOrNullableType()) throw AssertionError("Should be primitive or nullable primitive type: $arg0Type") + if (!arg0Type.isPrimitiveNumberOrNullableType() && !arg0Type.upperBoundedByPrimitiveNumberOrNullableType()) + throw AssertionError("Should be primitive or nullable primitive type: $arg0Type") val arg1Type = expression.getValueArgument(1)!!.type.toKotlinType() - if (!arg1Type.isPrimitiveNumberOrNullableType()) throw AssertionError("Should be primitive or nullable primitive type: $arg1Type") + if (!arg1Type.isPrimitiveNumberOrNullableType() && !arg1Type.upperBoundedByPrimitiveNumberOrNullableType()) + throw AssertionError("Should be primitive or nullable primitive type: $arg1Type") val arg0isNullable = arg0Type.isMarkedNullable val arg1isNullable = arg1Type.isMarkedNullable @@ -124,7 +127,6 @@ class Ieee754Equals(val operandType: Type) : IntrinsicMethod() { Ieee754AreEqual(boxedOperandType, boxedOperandType) } } - } class TotalOrderEquals(operandType: Type) : IntrinsicMethod() { diff --git a/compiler/testData/codegen/box/ieee754/equalsNaN_properIeeeComparisons.kt b/compiler/testData/codegen/box/ieee754/equalsNaN_properIeeeComparisons.kt index 13a99440bea..b87dfcd29e5 100644 --- a/compiler/testData/codegen/box/ieee754/equalsNaN_properIeeeComparisons.kt +++ b/compiler/testData/codegen/box/ieee754/equalsNaN_properIeeeComparisons.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +ProperIeee754Comparisons -// IGNORE_BACKEND: JVM_IR // WITH_RUNTIME import kotlin.test.* diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 6a648da508e..b888751cda2 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -80,6 +80,9 @@ fun KotlinType.isPrimitiveNumberOrNullableType(): Boolean = fun KotlinType.isTypeParameter(): Boolean = TypeUtils.isTypeParameter(this) +fun KotlinType.upperBoundedByPrimitiveNumberOrNullableType(): Boolean = + TypeUtils.getTypeParameterDescriptorOrNull(this)?.upperBounds?.any { it.isPrimitiveNumberOrNullableType() } == true + fun KotlinType.isInterface(): Boolean = (constructor.declarationDescriptor as? ClassDescriptor)?.kind == ClassKind.INTERFACE fun KotlinType.isEnum(): Boolean = (constructor.declarationDescriptor as? ClassDescriptor)?.kind == ClassKind.ENUM_CLASS