Repository: microsoft/regorus (language: python)

Issue:
Is the `import` statement fully supported?
In Regorus, the following code works.

```
package semconv
import rego.v1

# Collect all attributes from previous groups that are prefixed by "registry."
prev_attributes := {attr.name | 
    some g in data.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

# Collect all attributes from current groups that are prefixed by "registry."
curr_attributes := {attr.name | 
    some g in input.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

prev_group_id_containing_attr := {attr.name: g.id |
    some g in data.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}
```

But not this one (see the `import` with the alias).
Note that the official implementation doesn't complain with this code. Is there something I'm missing?

```
package semconv
import rego.v1

# HERE I DEFINED AN ALIAS TO data.groups 
import data.groups as prev_groups

# Collect all attributes from previous groups that are prefixed by "registry."
prev_attributes := {attr.name | 
    some g in prev_groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

# Collect all attributes from current groups that are prefixed by "registry."
curr_attributes := {attr.name | 
    some g in input.groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}

prev_group_id_containing_attr := {attr.name: g.id |
    some g in prev_groups
    startswith(g.id, "registry.")
    some attr in g.attributes
}
```




Discussion / hints:

Fix patch:
diff --git a/src/lib.rs b/src/lib.rs
index 39f84b2e..cf0b7f94 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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.
diff --git a/src/scheduler.rs b/src/scheduler.rs
index b5469d93..17815424 100644
--- a/src/scheduler.rs
+++ b/src/scheduler.rs
@@ -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(())


Test patch:
diff --git a/tests/interpreter/cases/import/tests.yaml b/tests/interpreter/cases/import/tests.yaml
index b67db954..721a4adc 100644
--- a/tests/interpreter/cases/import/tests.yaml
+++ b/tests/interpreter/cases/import/tests.yaml
@@ -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: