Skip to content

Commit

Permalink
genpolicy tweaks (microsoft#141)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
anakrish authored Feb 12, 2024
1 parent 3b2e639 commit 13eb06e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/builtins/debugging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn print(span: &Span, _params: &[Ref<Expr>], args: &[Value], _strict: bool) -> R
}

if !msg.is_empty() {
println!("{}", &msg[1..]);
eprintln!("{}", &msg[1..]);
}
Ok(Value::Bool(true))
}
13 changes: 12 additions & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions tests/interpreter/cases/import/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

0 comments on commit 13eb06e

Please sign in to comment.