Skip to content

Commit

Permalink
fix: fix check config visited entry.value twice
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa committed Jul 15, 2024
1 parent eb63521 commit 9168b1b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl<'ctx> Resolver<'ctx> {
pub(crate) fn check_config_entry(
&mut self,
key: &'ctx Option<ast::NodeRef<ast::Expr>>,
value: &'ctx ast::NodeRef<ast::Expr>,
value_ty: TypeRef,
) {
if let Some(key) = key {
if let Some(Some(_)) = self.ctx.config_expr_context.last() {
Expand Down Expand Up @@ -359,7 +359,7 @@ impl<'ctx> Resolver<'ctx> {
self.check_config_expr_by_key_name(name, key);
stack_depth += self.switch_config_expr_context_by_name(name);
}
let mut val_ty = self.expr(value);
let mut val_ty = value_ty.clone();
for _ in 0..names.len() - 1 {
val_ty = Type::dict_ref(self.str_ty(), val_ty);
}
Expand Down Expand Up @@ -539,13 +539,14 @@ impl<'ctx> Resolver<'ctx> {
let value = &item.node.value;
let op = &item.node.operation;
let mut stack_depth: usize = 0;
self.check_config_entry(key, value);
let value_ty = self.expr(value);
self.check_config_entry(key, value_ty.clone());
stack_depth += self.switch_config_expr_context_by_key(key);
let mut has_insert_index = false;
let val_ty = match key {
Some(key) => match &key.node {
ast::Expr::Identifier(identifier) => {
let mut val_ty = self.expr(value);
let mut val_ty = value_ty.clone();

for _ in 0..identifier.names.len() - 1 {
val_ty = Type::dict_ref(self.str_ty(), val_ty.clone());
Expand Down Expand Up @@ -597,7 +598,7 @@ impl<'ctx> Resolver<'ctx> {
if matches!(subscript.value.node, ast::Expr::Identifier(_)) =>
{
has_insert_index = true;
let val_ty = self.expr(value);
let val_ty = value_ty.clone();
key_types.push(self.str_ty());
val_types.push(Type::list_ref(val_ty.clone()));
val_ty
Expand All @@ -607,7 +608,7 @@ impl<'ctx> Resolver<'ctx> {
self.ctx.config_expr_context.push(None);
let key_ty = self.expr(key);
self.ctx.config_expr_context.pop();
let val_ty = self.expr(value);
let val_ty = value_ty.clone();
self.check_attr_ty(&key_ty, key.get_span_pos());
if let ast::Expr::StringLit(string_lit) = &key.node {
let ty = if let Some(attr) = attrs.get(&string_lit.value) {
Expand Down Expand Up @@ -640,7 +641,7 @@ impl<'ctx> Resolver<'ctx> {
}
},
None => {
let val_ty = self.expr(value);
let val_ty = value_ty.clone();
match &val_ty.kind {
TypeKind::None | TypeKind::Any => {
val_types.push(val_ty.clone());
Expand Down

0 comments on commit 9168b1b

Please sign in to comment.