Fix unhandled exceptions when evaluating operators (#1344)

This commit is contained in:
altrisi authored and GitHub committed 2022-02-20 19:15:54 +01:00
1 parent 692e157905
commit e011f65e75
1 file changed
+22 -18
+22 -18
View File
@@ -238,14 +238,16 @@ public abstract class Fluff
@Override @Override
public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2) public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2)
{ {
try return (c, typeIgnored) -> {
{ try
return (c, type_ignored) -> AbstractOperator.this.eval(v1.evalValue(c, Context.Type.NONE), v2.evalValue(c, Context.Type.NONE)); {
} return AbstractOperator.this.eval(v1.evalValue(c, Context.Type.NONE), v2.evalValue(c, Context.Type.NONE));
catch (RuntimeException exc) }
{ catch (RuntimeException exc)
throw Expression.handleCodeException(cc, exc, e, t); {
} throw Expression.handleCodeException(cc, exc, e, t);
}
};
} }
} }
@@ -267,24 +269,26 @@ public abstract class Fluff
@Override @Override
public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2) public LazyValue lazyEval(Context cc, Context.Type type, Expression e, Tokenizer.Token t, final LazyValue v1, final LazyValue v2)
{ {
try if (v2 != null)
{ {
if (v2 != null) throw new ExpressionException(cc, e, t, "Did not expect a second parameter for unary operator");
}
return (c, ignoredType) -> {
try
{ {
throw new ExpressionException(cc, e, t, "Did not expect a second parameter for unary operator"); return AbstractUnaryOperator.this.evalUnary(v1.evalValue(c, Context.Type.NONE));
} }
return (c, ignored_type) -> AbstractUnaryOperator.this.evalUnary(v1.evalValue(c, Context.Type.NONE)); catch (RuntimeException exc)
} {
catch (RuntimeException exc) throw Expression.handleCodeException(cc, exc, e, t);
{ }
throw Expression.handleCodeException(cc, exc, e, t); };
}
} }
@Override @Override
public Value eval(Value v1, Value v2) public Value eval(Value v1, Value v2)
{ {
throw new RuntimeException("Shouldn't end up here"); throw new IllegalStateException("Shouldn't end up here");
} }
public abstract Value evalUnary(Value v1); public abstract Value evalUnary(Value v1);