Skip to content

Commit

Permalink
fix: fix positional argument error missing (#877)
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe authored Nov 14, 2023
1 parent 55ad0ee commit b839107
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kclvm/sema/src/resolver/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ impl<'ctx> Resolver<'ctx> {
params.push(Parameter {
name,
ty: ty.clone(),
has_default: args.node.defaults.get(i).is_some(),
has_default: args.node.defaults.get(i).map_or(false, |arg| arg.is_some()),
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions kclvm/sema/src/resolver/test_data/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[package]

6 changes: 6 additions & 0 deletions kclvm/sema/src/resolver/test_data/schema_params_miss.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schema D[name: str]: # ''
n: str = name

d = D() { # expected 1 positional argument, found 0
n = ""
}
24 changes: 24 additions & 0 deletions kclvm/sema/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,3 +719,27 @@ fn undef_lambda_param() {
)
);
}

#[test]
fn test_schema_params_count() {
let sess = Arc::new(ParseSession::default());
let mut program = load_program(
sess.clone(),
&["./src/resolver/test_data/schema_params_miss.k"],
None,
None,
)
.unwrap();
let scope = resolve_program(&mut program);
assert_eq!(scope.handler.diagnostics.len(), 1);
let diag = &scope.handler.diagnostics[0];
assert_eq!(
diag.code,
Some(DiagnosticId::Error(ErrorKind::CompileError))
);
assert_eq!(diag.messages.len(), 1);
assert_eq!(
diag.messages[0].message,
"expected 1 positional argument, found 0"
);
}

0 comments on commit b839107

Please sign in to comment.