mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
fix: Handle aliases in scheduler (#285)
Earlier scheduler only recognized rules and would raise an `unsafe var` error on alias. Register alias var names to fix this. fixes #284 Also fix clippy warning treated as error Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
6e1f8cdb36
commit
7095e269b7
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#![allow(unknown_lints)]
|
||||
#![allow(clippy::doc_lazy_continuation)]
|
||||
// Use README.md as crate documentation.
|
||||
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
|
||||
// We'll default to building for no_std - use core, alloc instead of std.
|
||||
|
||||
@@ -412,7 +412,7 @@ impl Analyzer {
|
||||
}
|
||||
|
||||
pub fn analyze(mut self, modules: &[Ref<Module>]) -> Result<Schedule> {
|
||||
self.add_rules(modules)?;
|
||||
self.add_rules_and_aliases(modules)?;
|
||||
self.functions = gather_functions(modules)?;
|
||||
|
||||
for m in modules {
|
||||
@@ -430,7 +430,7 @@ impl Analyzer {
|
||||
modules: &[Ref<Module>],
|
||||
query: &Ref<Query>,
|
||||
) -> Result<Schedule> {
|
||||
self.add_rules(modules)?;
|
||||
self.add_rules_and_aliases(modules)?;
|
||||
self.analyze_query(None, None, query, Scope::default())?;
|
||||
|
||||
Ok(Schedule {
|
||||
@@ -439,7 +439,7 @@ impl Analyzer {
|
||||
})
|
||||
}
|
||||
|
||||
fn add_rules(&mut self, modules: &[Ref<Module>]) -> Result<()> {
|
||||
fn add_rules_and_aliases(&mut self, modules: &[Ref<Module>]) -> Result<()> {
|
||||
for m in modules {
|
||||
let path = get_path_string(&m.package.refr, Some("data"))?;
|
||||
let scope: &mut Scope = self.packages.entry(path).or_default();
|
||||
@@ -456,6 +456,12 @@ impl Analyzer {
|
||||
};
|
||||
scope.unscoped.insert(var);
|
||||
}
|
||||
|
||||
for import in &m.imports {
|
||||
if let Some(var) = &import.r#as {
|
||||
scope.unscoped.insert(var.source_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -34,6 +34,7 @@ cases:
|
||||
|
||||
- |
|
||||
package b
|
||||
import rego.v1
|
||||
# Both the following imports are overridden by rules
|
||||
#import data.a.b as a
|
||||
#import data.a.b
|
||||
@@ -43,6 +44,10 @@ cases:
|
||||
|
||||
a = 10
|
||||
c = C + b
|
||||
|
||||
r if {
|
||||
some v in [C]
|
||||
}
|
||||
query: data
|
||||
want_result:
|
||||
a:
|
||||
@@ -50,6 +55,7 @@ cases:
|
||||
b:
|
||||
a: 10
|
||||
c: 22
|
||||
r: true
|
||||
|
||||
- note: import overridden by rule
|
||||
modules:
|
||||
|
||||
Reference in New Issue
Block a user