diff --git a/kclvm/evaluator/src/node.rs b/kclvm/evaluator/src/node.rs index a80f99504..68dffc920 100644 --- a/kclvm/evaluator/src/node.rs +++ b/kclvm/evaluator/src/node.rs @@ -78,48 +78,17 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> { self.add_target_var(name); // The right value of the unification_stmt is a schema_expr. let value = self.walk_schema_expr(&unification_stmt.value.node)?; - if self.scope_level() == GLOBAL_LEVEL || self.is_in_lambda() { - if self.resolve_variable(name) { - let mut org_value = self.walk_identifier_with_ctx( - &unification_stmt.target.node, - &ast::ExprContext::Load, - None, - )?; - let value = org_value.bin_aug_bit_or(&mut self.runtime_ctx.borrow_mut(), &value); - // Store the identifier value - self.walk_identifier_with_ctx( - &unification_stmt.target.node, - &ast::ExprContext::Store, - Some(value.clone()), - )?; - return Ok(value.clone()); - } else { - self.walk_identifier_with_ctx( - &unification_stmt.target.node, - &unification_stmt.target.node.ctx, - Some(value.clone()), - )?; - return Ok(value); - } - // Local variables including schema/rule/lambda - } else if self.is_in_schema() { - // Load the identifier value - let org_value = self - .walk_identifier_with_ctx( - &unification_stmt.target.node, - &ast::ExprContext::Load, - None, - ) - .unwrap_or(self.undefined_value()); - let value = self.bit_or(org_value, value); - // Store the identifier value - self.walk_identifier_with_ctx( - &unification_stmt.target.node, - &ast::ExprContext::Store, - Some(value.clone()), - )?; - return Ok(value); - } + // Load the identifier value + let org_value = self + .walk_identifier_with_ctx(&unification_stmt.target.node, &ast::ExprContext::Load, None) + .unwrap_or(self.undefined_value()); + let value = self.bit_or(org_value, value); + // Store the identifier value + self.walk_identifier_with_ctx( + &unification_stmt.target.node, + &ast::ExprContext::Store, + Some(value.clone()), + )?; self.pop_target_var(); Ok(value) } diff --git a/test/grammar/schema/config_op/union/union_3/main.k b/test/grammar/schema/config_op/union/union_3/main.k new file mode 100644 index 000000000..5fd791c44 --- /dev/null +++ b/test/grammar/schema/config_op/union/union_3/main.k @@ -0,0 +1,62 @@ +schema ResourceMapping: + [str]: any + +schema BaseFrontend: + name: str + +protocol MixinProtocol: + count: int + resources: ResourceMapping + +mixin Mixin1Mixin for MixinProtocol: + resources: ResourceMapping { + resource1 += [{ + a = "a" + }] + } + count += 1 + +mixin Mixin2Mixin for MixinProtocol: + resources: ResourceMapping { + resource2 += [{ + b = "b" + }] + } + count += 1 + +mixin Mixin3Mixin for MixinProtocol: + resources: ResourceMapping { + resource3 += [{ + c = "c" + }] + } + count += 1 + +schema BaseBackend[a: BaseFrontend]: + mixin [ + Mixin1Mixin, + Mixin2Mixin, + Mixin3Mixin, + Mixin3Mixin, + ] + resources: ResourceMapping + count: int = 0 + +render = lambda a: BaseFrontend { + impl = BaseBackend(a) + impl +} +frontEnd = BaseFrontend {name = "app"} +res1 = [render(a) for a in BaseFrontend.instances()] +res2 = [BaseBackend(a) for a in BaseFrontend.instances()] +resources: ResourceMapping {} +resources: ResourceMapping { + resource1 += [{ + a = "a" + }] +} +resources: ResourceMapping { + resource2 += [{ + b = "b" + }] +} diff --git a/test/grammar/schema/config_op/union/union_3/stdout.golden b/test/grammar/schema/config_op/union/union_3/stdout.golden new file mode 100644 index 000000000..9b19f672b --- /dev/null +++ b/test/grammar/schema/config_op/union/union_3/stdout.golden @@ -0,0 +1,27 @@ +frontEnd: + name: app +res1: +- resources: + resource1: + - a: a + resource2: + - b: b + resource3: + - c: c + - c: c + count: 4 +res2: +- resources: + resource1: + - a: a + resource2: + - b: b + resource3: + - c: c + - c: c + count: 4 +resources: + resource1: + - a: a + resource2: + - b: b