Rename method checkForError to replaceIfError
This name better reflects the point of this method. a.replaceIfError(b) will return b instead of a in case a is an error expression
This commit is contained in:
@@ -23,17 +23,17 @@ import org.jetbrains.kotlin.ir.types.isArray
|
|||||||
import org.jetbrains.kotlin.ir.types.typeOrNull
|
import org.jetbrains.kotlin.ir.types.typeOrNull
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
|
//TODO create abstract class that will be common for this and lowering
|
||||||
class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransformerVoid() {
|
class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransformerVoid() {
|
||||||
private val interpreter = IrInterpreter(irModuleFragment)
|
private val interpreter = IrInterpreter(irModuleFragment)
|
||||||
|
|
||||||
private fun IrExpression.report(original: IrExpression): IrExpression {
|
private fun IrExpression.replaceIfError(original: IrExpression): IrExpression {
|
||||||
if (this == original) return this
|
|
||||||
return if (this !is IrErrorExpression) this else original
|
return if (this !is IrErrorExpression) this else original
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
if (expression.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
if (expression.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
||||||
return interpreter.interpret(expression).report(expression)
|
return interpreter.interpret(expression).replaceIfError(expression)
|
||||||
}
|
}
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransfor
|
|||||||
if (isConst && !isCompileTimeComputable) {
|
if (isConst && !isCompileTimeComputable) {
|
||||||
//throw AssertionError("Const property is used only with functions annotated as CompileTimeCalculation: " + declaration.dump())
|
//throw AssertionError("Const property is used only with functions annotated as CompileTimeCalculation: " + declaration.dump())
|
||||||
} else if (isCompileTimeComputable) {
|
} else if (isCompileTimeComputable) {
|
||||||
initializer.expression = interpreter.interpret(expression).report(expression)
|
initializer.expression = interpreter.interpret(expression).replaceIfError(expression)
|
||||||
}
|
}
|
||||||
return declaration
|
return declaration
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ class IrConstTransformer(irModuleFragment: IrModuleFragment) : IrElementTransfor
|
|||||||
for (i in 0 until it.valueArgumentsCount) {
|
for (i in 0 until it.valueArgumentsCount) {
|
||||||
val arg = it.getValueArgument(i) ?: continue
|
val arg = it.getValueArgument(i) ?: continue
|
||||||
if (arg.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
if (arg.accept(IrCompileTimeChecker(mode = EvaluationMode.ONLY_BUILTINS), null)) {
|
||||||
val const = interpreter.interpret(arg).report(arg)
|
val const = interpreter.interpret(arg).replaceIfError(arg)
|
||||||
it.putValueArgument(i, const.convertToConstIfPossible(it.symbol.owner.valueParameters[i].type))
|
it.putValueArgument(i, const.convertToConstIfPossible(it.symbol.owner.valueParameters[i].type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user