mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Make unary - operator OPA compatible. (#175)
OPA supports unary - operator only in the following cases: -\s+numeric literal We match OPAs behavior for now. This can be revisited later.
This commit is contained in:
committed by
GitHub
parent
08f3007b5c
commit
7bc9a50a52
@@ -2699,7 +2699,22 @@ impl Interpreter {
|
||||
key, value, query, ..
|
||||
} => self.eval_object_compr(key, value, query),
|
||||
Expr::SetCompr { term, query, .. } => self.eval_set_compr(term, query),
|
||||
Expr::UnaryExpr { .. } => unimplemented!("unar expr is umplemented"),
|
||||
Expr::UnaryExpr { span, expr: uexpr } => match uexpr.as_ref() {
|
||||
Expr::Number(_) if !uexpr.span().text().starts_with('-') => {
|
||||
builtins::numbers::arithmetic_operation(
|
||||
span,
|
||||
&ArithOp::Sub,
|
||||
expr,
|
||||
uexpr,
|
||||
Value::from(0),
|
||||
self.eval_expr(uexpr)?,
|
||||
self.strict_builtin_errors,
|
||||
)
|
||||
}
|
||||
_ => bail!(expr
|
||||
.span()
|
||||
.error("unary - can only be used with numeric literals")),
|
||||
},
|
||||
Expr::Call { span, fcn, params } => {
|
||||
self.eval_call(span, expr, fcn, params, None, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user