Fix type of IllegalArgumentException call for illegal step in StepHandler.
This commit is contained in:
committed by
max-kammerer
parent
ca4784ffd3
commit
f2289c216c
+12
-9
@@ -329,15 +329,18 @@ internal class HeaderProcessor(
|
|||||||
)
|
)
|
||||||
} else null
|
} else null
|
||||||
|
|
||||||
val stepVariable = scope.createTemporaryVariable(
|
val stepVariable = headerInfo.progressionType.stepType(context.irBuiltIns).let {
|
||||||
ensureNotNullable(
|
scope.createTemporaryVariable(
|
||||||
headerInfo.step.castIfNecessary(
|
ensureNotNullable(
|
||||||
headerInfo.progressionType.stepType(context.irBuiltIns),
|
headerInfo.step.castIfNecessary(
|
||||||
headerInfo.progressionType.stepCastFunctionName
|
it,
|
||||||
)
|
headerInfo.progressionType.stepCastFunctionName
|
||||||
),
|
)
|
||||||
nameHint = "step"
|
),
|
||||||
)
|
nameHint = "step",
|
||||||
|
irType = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return when (headerInfo) {
|
return when (headerInfo) {
|
||||||
is IndexedGetHeaderInfo -> IndexedGetLoopHeader(
|
is IndexedGetHeaderInfo -> IndexedGetLoopHeader(
|
||||||
|
|||||||
+1
-1
@@ -261,7 +261,7 @@ internal class StepHandler(
|
|||||||
val stepGreaterFun = context.irBuiltIns.greaterFunByOperandType[stepType.toKotlinType()]!!
|
val stepGreaterFun = context.irBuiltIns.greaterFunByOperandType[stepType.toKotlinType()]!!
|
||||||
val zeroStep = if (data == ProgressionType.LONG_PROGRESSION) irLong(0) else irInt(0)
|
val zeroStep = if (data == ProgressionType.LONG_PROGRESSION) irLong(0) else irInt(0)
|
||||||
val throwIllegalStepExceptionCall = {
|
val throwIllegalStepExceptionCall = {
|
||||||
irCall(context.irBuiltIns.illegalArgumentExceptionSymbol, stepType).apply {
|
irCall(context.irBuiltIns.illegalArgumentExceptionSymbol).apply {
|
||||||
val exceptionMessage = irConcat()
|
val exceptionMessage = irConcat()
|
||||||
exceptionMessage.addArgument(irString("Step must be positive, was: "))
|
exceptionMessage.addArgument(irString("Step must be positive, was: "))
|
||||||
exceptionMessage.addArgument(stepArgExpression.deepCopyWithSymbols())
|
exceptionMessage.addArgument(stepArgExpression.deepCopyWithSymbols())
|
||||||
|
|||||||
+8
-3
@@ -15,16 +15,18 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.getClass
|
import org.jetbrains.kotlin.ir.types.getClass
|
||||||
|
import org.jetbrains.kotlin.ir.types.isNothing
|
||||||
import org.jetbrains.kotlin.ir.util.functions
|
import org.jetbrains.kotlin.ir.util.functions
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
internal fun IrExpression.castIfNecessary(targetType: IrType, numberCastFunctionName: Name): IrExpression {
|
internal fun IrExpression.castIfNecessary(targetType: IrType, numberCastFunctionName: Name): IrExpression {
|
||||||
return if (type == targetType) {
|
// This expression's type could be Nothing from an exception throw.
|
||||||
|
return if (type == targetType || type.isNothing()) {
|
||||||
this
|
this
|
||||||
} else {
|
} else {
|
||||||
val function = type.getClass()!!.functions.first { it.name == numberCastFunctionName }
|
val castFun = type.getClass()!!.functions.first { it.name == numberCastFunctionName }
|
||||||
IrCallImpl(startOffset, endOffset, function.returnType, function.symbol)
|
IrCallImpl(startOffset, endOffset, castFun.returnType, castFun.symbol)
|
||||||
.apply { dispatchReceiver = this@castIfNecessary }
|
.apply { dispatchReceiver = this@castIfNecessary }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,6 +37,9 @@ internal fun IrExpression.negate(): IrExpression {
|
|||||||
is Int -> IrConstImpl(startOffset, endOffset, type, IrConstKind.Int, -value)
|
is Int -> IrConstImpl(startOffset, endOffset, type, IrConstKind.Int, -value)
|
||||||
is Long -> IrConstImpl(startOffset, endOffset, type, IrConstKind.Long, -value)
|
is Long -> IrConstImpl(startOffset, endOffset, type, IrConstKind.Long, -value)
|
||||||
else -> {
|
else -> {
|
||||||
|
// This expression's type could be Nothing from an exception throw, in which case the unary minus function will not exist.
|
||||||
|
if (type.isNothing()) return this
|
||||||
|
|
||||||
val unaryMinusFun = type.getClass()!!.functions.first { it.name == OperatorNameConventions.UNARY_MINUS }
|
val unaryMinusFun = type.getClass()!!.functions.first { it.name == OperatorNameConventions.UNARY_MINUS }
|
||||||
IrCallImpl(startOffset, endOffset, type, unaryMinusFun.symbol, unaryMinusFun.descriptor).apply {
|
IrCallImpl(startOffset, endOffset, type, unaryMinusFun.symbol, unaryMinusFun.descriptor).apply {
|
||||||
dispatchReceiver = this@negate
|
dispatchReceiver = this@negate
|
||||||
|
|||||||
Reference in New Issue
Block a user