From 936cbbd4ec4cd1c76faf92c7f26475d4812e5690 Mon Sep 17 00:00:00 2001 From: He1pa <56333845+He1pa@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:09:05 +0800 Subject: [PATCH] remove unwrap in advanced_resolver walk_call() (#1506) Signed-off-by: he1pa <18012015693@163.com> --- kclvm/sema/src/advanced_resolver/node.rs | 47 ++++++++++++------------ 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index dd5ed1cf3..e58aa43fd 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -579,36 +579,37 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { let start = call_expr.func.get_end_pos(); let end = self.ctx.end_pos.clone(); let func_symbol = self.expr(&call_expr.func)?; - let ty = self + let call_ty = self .ctx .node_ty_map .borrow() .get(&self.ctx.get_node_key(&call_expr.func.id)) - .unwrap() - .clone(); + .map(|ty| ty.clone()); + + if let Some(ty) = call_ty { + if let TypeKind::Function(func_ty) = &ty.kind { + self.enter_local_scope( + &self.ctx.current_filename.as_ref().unwrap().clone(), + start, + end, + LocalSymbolScopeKind::Callable, + ); - if let TypeKind::Function(func_ty) = &ty.kind { - self.enter_local_scope( - &self.ctx.current_filename.as_ref().unwrap().clone(), - start, - end, - LocalSymbolScopeKind::Callable, - ); + if let Some(owner) = func_symbol { + let cur_scope = self.ctx.scopes.last().unwrap(); + self.gs + .get_scopes_mut() + .set_owner_to_scope(*cur_scope, owner); + } - if let Some(owner) = func_symbol { - let cur_scope = self.ctx.scopes.last().unwrap(); - self.gs - .get_scopes_mut() - .set_owner_to_scope(*cur_scope, owner); + self.do_arguments_symbol_resolve_with_hint( + &call_expr.args, + &call_expr.keywords, + true, + &func_ty, + )?; + self.leave_scope(); } - - self.do_arguments_symbol_resolve_with_hint( - &call_expr.args, - &call_expr.keywords, - true, - &func_ty, - )?; - self.leave_scope(); } Ok(None)