Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix ty error in assignment #900

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions kclvm/sema/src/resolver/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
value_ty = self.expr(&assign_stmt.value);
self.clear_config_expr_context(init_stack_depth as usize, false)
}
TypeKind::Dict(_) => {
value_ty = self.expr(&assign_stmt.value);
if !assign_stmt.type_annotation.is_none() {
// Check type annotation if exists.
self.check_assignment_type_annotation(assign_stmt, value_ty.clone());
}
self.set_type_to_scope(name, value_ty.clone(), &target.node.names[0]);
}
_ => {
value_ty = self.expr(&assign_stmt.value);
// Check type annotation if exists.
Expand Down
9 changes: 9 additions & 0 deletions kclvm/sema/src/resolver/test_data/ty_in_lambda.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_b = True
a = lambda item: {str:}, c: {str:} -> {str:str} {
result = {"aaa": "bbb"}
if _b :
result = {}
result
}

result = {"ccc": "ddd"}
25 changes: 25 additions & 0 deletions kclvm/sema/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,28 @@ fn test_schema_params_count() {
"expected 1 positional argument, found 0"
);
}

#[test]
fn test_set_ty_in_lambda() {
let sess = Arc::new(ParseSession::default());
let mut program = load_program(
sess.clone(),
&["./src/resolver/test_data/ty_in_lambda.k"],
None,
None,
)
.unwrap();
assert_eq!(
resolve_program(&mut program)
.main_scope()
.unwrap()
.borrow()
.lookup("result")
.unwrap()
.borrow()
.ty
.clone()
.ty_str(),
"{str:str}"
);
}
21 changes: 21 additions & 0 deletions kclvm/tools/src/LSP/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,27 @@ mod tests {
}
}

#[test]
#[bench_test]
fn assignment_ty_in_lambda_hover() {
let (file, program, prog_scope, _, gs) =
compile_test_file("src/test_data/hover_test/ty_in_lambda.k");
let pos = KCLPos {
filename: file.clone(),
line: 3,
column: Some(8),
};
let got = hover(&program, &pos, &prog_scope, &gs).unwrap();
match got.contents {
lsp_types::HoverContents::Scalar(marked_string) => {
if let MarkedString::String(s) = marked_string {
assert_eq!(s, "result: {str:str}");
}
}
_ => unreachable!("test error"),
}
}

#[test]
#[bench_test]
fn str_var_func_hover() {
Expand Down
9 changes: 9 additions & 0 deletions kclvm/tools/src/LSP/src/test_data/hover_test/ty_in_lambda.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_b = True
a = lambda item: {str:}, c: {str:} -> {str:str} {
result = {"aaa": "bbb"}
if _b :
result = {}
result
}

result = {"ccc": "ddd"}