From 37fffd8a49d4b19e69310ec0f6d5aab1e744663a Mon Sep 17 00:00:00 2001 From: peefy Date: Mon, 4 Nov 2024 13:07:04 +0800 Subject: [PATCH] fix: evaluator on the base schema order Signed-off-by: peefy --- kclvm/evaluator/src/schema.rs | 12 ++++++++++-- .../grammar/schema/irrelevant_order/simple_12/main.k | 12 ++++++++++++ .../schema/irrelevant_order/simple_12/stdout.golden | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/grammar/schema/irrelevant_order/simple_12/main.k create mode 100644 test/grammar/schema/irrelevant_order/simple_12/stdout.golden diff --git a/kclvm/evaluator/src/schema.rs b/kclvm/evaluator/src/schema.rs index 1ab0baee5..93d832e75 100644 --- a/kclvm/evaluator/src/schema.rs +++ b/kclvm/evaluator/src/schema.rs @@ -105,14 +105,22 @@ impl SchemaEvalContext { self.optional_mapping = other.optional_mapping.clone(); self.is_sub_schema = false; // Set lazy eval scope. - if let Some(scope) = &self.scope { - if let Some(other) = &other.scope { + if let Some(other) = &other.scope { + if let Some(scope) = &self.scope { let mut scope = scope.borrow_mut(); let other = other.borrow(); scope.cache = other.cache.clone(); scope.levels = other.levels.clone(); scope.cal_times = other.cal_times.clone(); scope.setters = other.setters.clone(); + } else { + let other = other.borrow(); + self.scope = Some(Rc::new(RefCell::new(LazyEvalScope { + cache: other.cache.clone(), + levels: other.levels.clone(), + cal_times: other.cal_times.clone(), + setters: other.setters.clone(), + }))) } } } diff --git a/test/grammar/schema/irrelevant_order/simple_12/main.k b/test/grammar/schema/irrelevant_order/simple_12/main.k new file mode 100644 index 000000000..148a00c5c --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_12/main.k @@ -0,0 +1,12 @@ +schema Derived1(Base): + name: str = "1" + +schema Base: + name: str + name2 = name + +schema Derived2(Base): + name: str = "2" + +d1 = Derived1 {} +d2 = Derived2 {} diff --git a/test/grammar/schema/irrelevant_order/simple_12/stdout.golden b/test/grammar/schema/irrelevant_order/simple_12/stdout.golden new file mode 100644 index 000000000..52980c233 --- /dev/null +++ b/test/grammar/schema/irrelevant_order/simple_12/stdout.golden @@ -0,0 +1,6 @@ +d1: + name: '1' + name2: '1' +d2: + name: '2' + name2: '2'