mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
early return (#189)
If a rule is written to produce a constant value, then not all iterations of loops
within it need to be executed. Execution can stop via early return once the first iteration
that produces a value has been executed.
This brings forth the question : What if one of the subsequent iterations would have resulted
in an error?
e.g:
x {
[1, "hello"][_] + 1
}
Such errors are not raised; consistent with OPA.
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
de56cce7cb
commit
316f3a7692
+11
-1
@@ -114,7 +114,17 @@ impl<'source> Parser<'source> {
|
||||
}
|
||||
Expr::Var(v) => comps.push(v.0.clone()),
|
||||
Expr::String(s) => comps.push(s.0.clone()),
|
||||
_ => bail!("internal error: not a simple ref"),
|
||||
Expr::True(s) | Expr::False(s) | Expr::Null(s) => comps.push(s.clone()),
|
||||
Expr::Number(s) => {
|
||||
// Ensure that the span will be the serialized representation.
|
||||
if *s.0.text() == s.1.to_json_str()? {
|
||||
comps.push(s.0.clone());
|
||||
} else {
|
||||
bail!(refr.span().error("not a valid ref"));
|
||||
}
|
||||
}
|
||||
|
||||
_ => bail!(refr.span().error("not a valid ref")),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user