From 13eb06e4be8607dbe1dfa9dc6793a121bb1ba222 Mon Sep 17 00:00:00 2001 From: Anand Krishnamoorthi <35780660+anakrish@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:52:12 -0800 Subject: [PATCH] genpolicy tweaks (#141) Allow `import input` instead of erroring out. This import is redundant and has no effect. Emit `print` messages to stderr onstead of stdout. Signed-off-by: Anand Krishnamoorthi --- src/builtins/debugging.rs | 2 +- src/interpreter.rs | 13 ++++++++++++- tests/interpreter/cases/import/tests.yaml | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/builtins/debugging.rs b/src/builtins/debugging.rs index b005c28..54c8f51 100644 --- a/src/builtins/debugging.rs +++ b/src/builtins/debugging.rs @@ -35,7 +35,7 @@ fn print(span: &Span, _params: &[Ref], args: &[Value], _strict: bool) -> R } if !msg.is_empty() { - println!("{}", &msg[1..]); + eprintln!("{}", &msg[1..]); } Ok(Value::Bool(true)) } diff --git a/src/interpreter.rs b/src/interpreter.rs index c5e088d..9646c23 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -3359,11 +3359,22 @@ impl Interpreter { Expr::String(s) => s.text(), _ => "", }, + Expr::Var(v) if v.text() == "input" => { + // Warn redundant import of input. Ignore it. + eprintln!( + "{}", + import.refr.span().error("redundant import of `input`") + ); + continue; + } _ => "", }, }; if target.is_empty() { - bail!(import.refr.span().error("invalid ref in import")); + bail!(import + .refr + .span() + .message("warning", "invalid ref in import")); } self.imports .insert(module_path.clone() + "." + target, import.refr.clone()); diff --git a/tests/interpreter/cases/import/tests.yaml b/tests/interpreter/cases/import/tests.yaml index 918b59d..b67db95 100644 --- a/tests/interpreter/cases/import/tests.yaml +++ b/tests/interpreter/cases/import/tests.yaml @@ -71,3 +71,11 @@ cases: import foo query: data error: "import path must begin with one of" + + - note: redundant import input + modules: + - | + package test + import input + query: data.test + want_result: {}