Skip to content

Commit c87b948

Browse files
committed
treat unknown as any
1 parent 093bd3e commit c87b948

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

crates/code_analysis/src/diagnostic/checker/param_type_check.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,49 @@ fn check_call_expr(
3535
}
3636

3737
if param.0 == "..." {
38+
if param.1.is_none() {
39+
break;
40+
}
41+
42+
let param_type = param.1.clone().unwrap();
43+
for arg in args.iter().skip(idx) {
44+
let mut expr_type = semantic_model
45+
.infer_expr(arg.clone())
46+
.unwrap_or(LuaType::Any);
47+
// treat unknown type as any
48+
if expr_type.is_unknown() {
49+
expr_type = LuaType::Any;
50+
}
51+
52+
if !semantic_model.check_type_compact(&param_type, &expr_type) {
53+
let db = semantic_model.get_db();
54+
context.add_diagnostic(
55+
DiagnosticCode::ParamTypeNotMatch,
56+
arg.get_range(),
57+
format!(
58+
"expected {} but founded {}",
59+
humanize_type(db, &param_type),
60+
humanize_type(db, &expr_type)
61+
),
62+
None,
63+
);
64+
}
65+
}
3866
} else {
3967
if param.1.is_none() {
4068
continue;
4169
}
4270

4371
let param_type = param.1.clone().unwrap();
4472
let arg = &args[idx];
45-
let expr_type = semantic_model
73+
let mut expr_type = semantic_model
4674
.infer_expr(arg.clone())
4775
.unwrap_or(LuaType::Any);
76+
// treat unknown type as any
77+
if expr_type.is_unknown() {
78+
expr_type = LuaType::Any;
79+
}
80+
4881
if !semantic_model.check_type_compact(&param_type, &expr_type) {
4982
let db = semantic_model.get_db();
5083
context.add_diagnostic(

0 commit comments

Comments
 (0)