avoid compiler crash when evaluating const expressions fails due to things like integer out of bounds

This commit is contained in:
Irmen de Jong 2021-03-04 01:32:02 +01:00
parent 96ba9f5902
commit 8dfe510883

View File

@ -9,6 +9,7 @@ import kotlin.math.pow
class ConstExprEvaluator {
fun evaluate(left: NumericLiteralValue, operator: String, right: NumericLiteralValue): Expression {
try {
return when(operator) {
"+" -> plus(left, right)
"-" -> minus(left, right)
@ -32,6 +33,9 @@ class ConstExprEvaluator {
">>" -> shiftedright(left, right)
else -> throw FatalAstException("const evaluation for invalid operator $operator")
}
} catch (ax: FatalAstException) {
throw ExpressionError(ax.message, left.position)
}
}
private fun shiftedright(left: NumericLiteralValue, amount: NumericLiteralValue): Expression {