From 862e134beab60fa3f8f22fd674aa673146b93cfb Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Thu, 1 Feb 2024 16:48:08 +0800 Subject: [PATCH] fix advanced resolver walk_list_if_item_expr Signed-off-by: he1pa <18012015693@163.com> --- kclvm/sema/src/advanced_resolver/node.rs | 1 + kclvm/tools/src/LSP/src/goto_def.rs | 15 +++++++++++++++ .../LSP/src/test_data/goto_def_test/goto_def.k | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index e1f4970a8..0307754b9 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -583,6 +583,7 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { &mut self, list_if_item_expr: &'ctx ast::ListIfItemExpr, ) -> Self::Result { + self.expr(&list_if_item_expr.if_cond)?; if let Some(orelse) = &list_if_item_expr.orelse { self.expr(orelse); } diff --git a/kclvm/tools/src/LSP/src/goto_def.rs b/kclvm/tools/src/LSP/src/goto_def.rs index 8350ddd42..dcedc7402 100644 --- a/kclvm/tools/src/LSP/src/goto_def.rs +++ b/kclvm/tools/src/LSP/src/goto_def.rs @@ -664,4 +664,19 @@ mod tests { let res = goto_definition_with_gs(&program, &pos, &gs); compare_goto_res(res, (&file, 84, 22, 84, 23)); } + + #[test] + #[bench_test] + fn list_if_expr_test() { + let (file, program, _, _, gs) = compile_test_file("src/test_data/goto_def_test/goto_def.k"); + + let pos = KCLPos { + filename: file.clone(), + line: 91, + column: Some(8), + }; + + let res = goto_definition_with_gs(&program, &pos, &gs); + compare_goto_res(res, (&file, 88, 0, 88, 1)); + } } diff --git a/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_def.k b/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_def.k index be64ba0ef..e40e42fc9 100644 --- a/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_def.k +++ b/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_def.k @@ -84,4 +84,10 @@ p4 = Person { func = lambda x: int, y: int -> int { x + y -} \ No newline at end of file +} + +b = True +command: [str] = [ + if b: + "a" +] \ No newline at end of file