mirror of
https://github.com/irmen/prog8.git
synced 2024-10-16 18:23:59 +00:00
avoid compiler crash when evaluating const expressions fails due to things like integer out of bounds
This commit is contained in:
parent
96ba9f5902
commit
8dfe510883
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user