Skip to content

Commit

Permalink
Fix: fix hidden global vars when merge in evaluator (#1811)
Browse files Browse the repository at this point in the history
* fix: fix hidden global vars when merge in evaluator

Signed-off-by: he1pa <18012015693@163.com>

* add ut

Signed-off-by: he1pa <18012015693@163.com>

* fix `show_hidden`

Signed-off-by: he1pa <18012015693@163.com>

* fmt

Signed-off-by: he1pa <18012015693@163.com>

---------

Signed-off-by: he1pa <18012015693@163.com>
  • Loading branch information
He1pa authored Jan 8, 2025
1 parent 69a4853 commit f368119
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kclvm/evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern crate kclvm_error;
use func::FunctionEvalContextRef;
use generational_arena::{Arena, Index};
use indexmap::IndexMap;
use kclvm_runtime::val_plan::KCL_PRIVATE_VAR_PREFIX;
use lazy::{BacktrackMeta, LazyEvalScope};
use proxy::{Frame, Proxy};
use rule::RuleEvalContextRef;
Expand Down Expand Up @@ -194,6 +195,11 @@ impl<'ctx> Evaluator<'ctx> {
}
// Deal global variables
for (name, value) in globals.iter() {
if name.starts_with(KCL_PRIVATE_VAR_PREFIX)
&& !self.runtime_ctx.borrow().plan_opts.show_hidden
{
continue;
}
let mut value_dict = self.dict_value();
self.dict_insert_merge_value(&mut value_dict, name.as_str(), value);
self.dict_insert_merge_value(&mut global_dict, SCALAR_KEY, &value_dict);
Expand Down
5 changes: 5 additions & 0 deletions test/grammar/scalar/hidden_var/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_a = 1

[
1
]
1 change: 1 addition & 0 deletions test/grammar/scalar/hidden_var/stdout.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1

0 comments on commit f368119

Please sign in to comment.