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 e61bd29
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions kclvm/sema/src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl<'ctx> Resolver<'ctx> {
&mut self,
key: &'ctx Option<ast::NodeRef<ast::Expr>>,
value: &'ctx ast::NodeRef<ast::Expr>,
) {
) -> Option<TypeRef> {
if let Some(key) = key {
if let Some(Some(_)) = self.ctx.config_expr_context.last() {
let mut has_index = false;
Expand All @@ -342,24 +342,26 @@ impl<'ctx> Resolver<'ctx> {
has_index = true;
identifier.get_names()
} else {
return;
return None;
}
} else {
return;
return None;
}
} else {
return;
return None;
}
}
ast::Expr::StringLit(string_lit) => vec![string_lit.value.clone()],
_ => return,
_ => return None,
};
let mut stack_depth = 0;
for name in &names {
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 return_ty = Some(val_ty.clone());

for _ in 0..names.len() - 1 {
val_ty = Type::dict_ref(self.str_ty(), val_ty);
}
Expand All @@ -376,8 +378,10 @@ impl<'ctx> Resolver<'ctx> {
);
}
self.clear_config_expr_context(stack_depth, false);
return return_ty;
}
}
None
}

pub(crate) fn get_config_attr_err_suggestion(
Expand Down Expand Up @@ -539,14 +543,15 @@ 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 mut val_ty = match self.check_config_entry(key, value) {
Some(ty) => ty,
None => self.expr(value),
};
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);

for _ in 0..identifier.names.len() - 1 {
val_ty = Type::dict_ref(self.str_ty(), val_ty.clone());
}
Expand Down Expand Up @@ -597,7 +602,6 @@ impl<'ctx> Resolver<'ctx> {
if matches!(subscript.value.node, ast::Expr::Identifier(_)) =>
{
has_insert_index = true;
let val_ty = self.expr(value);
key_types.push(self.str_ty());
val_types.push(Type::list_ref(val_ty.clone()));
val_ty
Expand All @@ -607,7 +611,6 @@ 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);
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 +643,6 @@ impl<'ctx> Resolver<'ctx> {
}
},
None => {
let val_ty = self.expr(value);
match &val_ty.kind {
TypeKind::None | TypeKind::Any => {
val_types.push(val_ty.clone());
Expand Down

0 comments on commit e61bd29

Please sign in to comment.