[IR] Fixed wrong IrCall type (to fix IR validation)
This commit is contained in:
+3
-3
@@ -60,17 +60,17 @@ fun IrStatement.isInductionVariable(context: CommonBackendContext) =
|
|||||||
origin == context.inductionVariableOrigin &&
|
origin == context.inductionVariableOrigin &&
|
||||||
name.asString() == inductionVariableName
|
name.asString() == inductionVariableName
|
||||||
|
|
||||||
internal class InitializerCallReplacer(private val replacementCall: IrCall) : IrElementTransformerVoid() {
|
internal class InitializerCallReplacer(private val replacement: IrExpression) : IrElementTransformerVoid() {
|
||||||
var initializerCall: IrCall? = null
|
var initializerCall: IrCall? = null
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrCall {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
if (initializerCall != null) {
|
if (initializerCall != null) {
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(
|
||||||
"Multiple initializer calls found. First: ${initializerCall!!.render()}\nSecond: ${expression.render()}"
|
"Multiple initializer calls found. First: ${initializerCall!!.render()}\nSecond: ${expression.render()}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
initializerCall = expression
|
initializerCall = expression
|
||||||
return replacementCall
|
return replacement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.declarations.IrVariable
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrWhileLoopImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrWhileLoopImpl
|
||||||
|
import org.jetbrains.kotlin.ir.util.implicitCastIfNeededTo
|
||||||
|
|
||||||
class IndexedGetLoopHeader(
|
class IndexedGetLoopHeader(
|
||||||
headerInfo: IndexedGetHeaderInfo,
|
headerInfo: IndexedGetHeaderInfo,
|
||||||
@@ -38,10 +39,10 @@ class IndexedGetLoopHeader(
|
|||||||
val indexedGetFun = with(headerInfo.expressionHandler) { headerInfo.objectVariable.type.getFunction }
|
val indexedGetFun = with(headerInfo.expressionHandler) { headerInfo.objectVariable.type.getFunction }
|
||||||
// Making sure that expression type has type of the variable when it exists.
|
// Making sure that expression type has type of the variable when it exists.
|
||||||
// Return type of get function can be a type parameter (for example Array<T>::get) which is not a subtype of loopVariable type.
|
// Return type of get function can be a type parameter (for example Array<T>::get) which is not a subtype of loopVariable type.
|
||||||
val get = irCall(indexedGetFun.symbol, type = loopVariable?.type ?: indexedGetFun.returnType).apply {
|
val get = irCall(indexedGetFun.symbol, indexedGetFun.returnType).apply {
|
||||||
dispatchReceiver = irGet(headerInfo.objectVariable)
|
dispatchReceiver = irGet(headerInfo.objectVariable)
|
||||||
putValueArgument(0, irGet(inductionVariable))
|
putValueArgument(0, irGet(inductionVariable))
|
||||||
}
|
}.implicitCastIfNeededTo(loopVariable?.type ?: indexedGetFun.returnType)
|
||||||
// The call could be wrapped in an IMPLICIT_NOTNULL type-cast (see comment in ForLoopsLowering.gatherLoopVariableInfo()).
|
// The call could be wrapped in an IMPLICIT_NOTNULL type-cast (see comment in ForLoopsLowering.gatherLoopVariableInfo()).
|
||||||
// Find and replace the call to preserve any type-casts.
|
// Find and replace the call to preserve any type-casts.
|
||||||
loopVariable?.initializer = loopVariable?.initializer?.transform(InitializerCallReplacer(get), null)
|
loopVariable?.initializer = loopVariable?.initializer?.transform(InitializerCallReplacer(get), null)
|
||||||
|
|||||||
+2
-2
@@ -33,13 +33,13 @@ internal fun IrExpression.negate(): IrExpression {
|
|||||||
it.valueParameters.isEmpty()
|
it.valueParameters.isEmpty()
|
||||||
}
|
}
|
||||||
IrCallImpl(
|
IrCallImpl(
|
||||||
startOffset, endOffset, type,
|
startOffset, endOffset, unaryMinusFun.returnType,
|
||||||
unaryMinusFun.symbol,
|
unaryMinusFun.symbol,
|
||||||
valueArgumentsCount = 0,
|
valueArgumentsCount = 0,
|
||||||
typeArgumentsCount = 0
|
typeArgumentsCount = 0
|
||||||
).apply {
|
).apply {
|
||||||
dispatchReceiver = this@negate
|
dispatchReceiver = this@negate
|
||||||
}
|
}.implicitCastIfNeededTo(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user