Skip to content

Commit

Permalink
bugfix: fix postion of undefined lambda param (kcl-lang#873)
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Nov 13, 2023
1 parent 5bc991c commit 441a2f5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kclvm/sema/src/resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,11 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
for (i, arg) in args.node.args.iter().enumerate() {
let name = arg.node.get_name();
let arg_ty = args.node.get_arg_type_node(i);
let ty = self.parse_ty_with_scope(arg_ty, arg.get_span_pos());
let range = match arg_ty {
Some(arg_type_node) => arg_type_node.get_span_pos(),
None => arg.get_span_pos(),
};
let ty = self.parse_ty_with_scope(arg_ty, range);

// If the arguments type of a lambda is a schema type,
// It should be marked as an schema instance type.
Expand Down
3 changes: 3 additions & 0 deletions kclvm/sema/src/resolver/test_data/undef_lambda_param.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lambda x: Undef { # 'Undef' is undefined
x
}
38 changes: 38 additions & 0 deletions kclvm/sema/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,41 @@ fn test_pkg_not_found_suggestion() {
"find more package on 'https://artifacthub.io'"
);
}

#[test]
fn undef_lambda_param() {
let sess = Arc::new(ParseSession::default());
let mut program = load_program(
sess.clone(),
&["./src/resolver/test_data/undef_lambda_param.k"],
None,
None,
)
.unwrap();
let scope = resolve_program(&mut program);
assert_eq!(scope.handler.diagnostics.len(), 1);

let root = &program.root.clone();
let filename = Path::new(&root.clone())
.join("undef_lambda_param.k")
.display()
.to_string();

let range = scope.handler.diagnostics[0].messages[0].range.clone();

assert_eq!(
range,
(
Position {
filename: filename.clone(),
line: 1,
column: Some(10),
},
Position {
filename: filename.clone(),
line: 1,
column: Some(15),
}
)
);
}

0 comments on commit 441a2f5

Please sign in to comment.