Fix an assertion for type parameters

This commit is contained in:
Ting-Yuan Huang
2019-03-21 16:46:07 -07:00
committed by Dmitry Petrov
parent acf8a0454f
commit 4ff2825de0
3 changed files with 8 additions and 4 deletions
@@ -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() {
@@ -1,5 +1,4 @@
// !LANGUAGE: +ProperIeee754Comparisons
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
import kotlin.test.*
@@ -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