Skip to content

Commit 0bad94a

Browse files
committed
Fix test
1 parent 69c398f commit 0bad94a

File tree

8 files changed

+175
-128
lines changed

8 files changed

+175
-128
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/lua/closure.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn analyze_return(
116116
let parent = closure.get_parent::<LuaAst>()?;
117117
match &parent {
118118
LuaAst::LuaCallArgList(_) => {
119-
analyze_lambda_returns(analyzer, signature_id, closure)?;
120-
return Some(());
119+
analyze_lambda_returns(analyzer, signature_id, closure);
121120
}
122121
_ => {}
123122
};

crates/emmylua_code_analysis/src/compilation/analyzer/unresolve/resolve_closure.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ pub fn try_resolve_closure_return(
171171
return try_convert_to_func_body_infer(db, cache, closure_return);
172172
}
173173

174+
match signature.resolve_return {
175+
SignatureReturnStatus::UnResolve => {}
176+
SignatureReturnStatus::InferResolve => {
177+
signature.return_docs.clear();
178+
}
179+
_ => return Some(true),
180+
}
181+
174182
signature.return_docs.push(LuaDocReturnInfo {
175183
name: None,
176184
type_ref: ret_type.clone(),

crates/emmylua_code_analysis/src/db_index/signature/signature.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ impl LuaSignature {
113113

114114
pub fn to_doc_func_type(&self) -> Arc<LuaFunctionType> {
115115
let params = self.get_type_params();
116-
let return_types = self.get_return_type();
116+
let return_type = self.get_return_type();
117117
let func_type =
118-
LuaFunctionType::new(self.is_async, self.is_colon_define, params, return_types);
118+
LuaFunctionType::new(self.is_async, self.is_colon_define, params, return_type);
119119
Arc::new(func_type)
120120
}
121121

@@ -125,8 +125,8 @@ impl LuaSignature {
125125
params.remove(0);
126126
}
127127

128-
let return_types = self.get_return_type();
129-
let func_type = LuaFunctionType::new(self.is_async, false, params, return_types);
128+
let return_type = self.get_return_type();
129+
let func_type = LuaFunctionType::new(self.is_async, false, params, return_type);
130130
Arc::new(func_type)
131131
}
132132
}

crates/emmylua_code_analysis/src/diagnostic/checker/check_param_count.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,6 @@ fn check_call_expr(
124124
}
125125
// 对调用参数的最后一个参数进行特殊处理
126126
if let Some(last_arg) = call_args.last() {
127-
// 如果最后一个参数是函数调用的结果, 那么需要判断他的函数签名返回值是否包含可变参数
128-
match last_arg {
129-
LuaExpr::CallExpr(call_expr) => {
130-
if let Some(func) = semantic_model.infer_call_expr_func(call_expr.clone(), None)
131-
{
132-
if func.get_ret().is_variadic() {
133-
return Some(());
134-
}
135-
}
136-
}
137-
_ => {}
138-
}
139-
140127
if let Ok(LuaType::Variadic(variadic)) = semantic_model.infer_expr(last_arg.clone()) {
141128
let len = match variadic.get_max_len() {
142129
Some(len) => len,

crates/emmylua_code_analysis/src/diagnostic/checker/check_return_count.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,27 @@ fn check_missing_return(
7171
return None;
7272
}
7373

74-
// 如果包含可变参数, 则跳过检查最大值
75-
// let skip_check_max =
76-
7774
// 最小返回值数
7875
let min_expected_return_count = match &return_type {
79-
LuaType::Variadic(variadic) => variadic.get_min_len()?,
76+
LuaType::Variadic(variadic) => {
77+
let min_len = variadic.get_min_len()?;
78+
let mut real_min_len = min_len;
79+
// 逆序检查
80+
if min_len > 0 {
81+
for i in (0..min_len).rev() {
82+
if let Some(ty) = variadic.get_type(i) {
83+
if ty.is_optional() {
84+
real_min_len -= 1;
85+
} else {
86+
break;
87+
}
88+
}
89+
}
90+
}
91+
real_min_len
92+
}
8093
LuaType::Nil | LuaType::Any | LuaType::Unknown => 0,
94+
_ if return_type.is_nullable() => 0,
8195
_ => 1,
8296
};
8397

@@ -250,7 +264,8 @@ fn check_return_count(
250264
) -> Option<()> {
251265
let max_expected_return_count = match return_type {
252266
LuaType::Variadic(variadic) => variadic.get_max_len(),
253-
LuaType::Nil | LuaType::Any | LuaType::Unknown => Some(1),
267+
LuaType::Any | LuaType::Unknown => Some(1),
268+
LuaType::Nil => Some(0),
254269
_ => Some(1),
255270
};
256271

crates/emmylua_code_analysis/src/diagnostic/checker/return_type_mismatch.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ fn check_return_stat(
104104
}
105105
}
106106
_ => {
107+
let mut check_type = return_type;
108+
if return_type.is_self_infer() {
109+
if let Some(self_type) = self_type {
110+
check_type = self_type;
111+
}
112+
}
107113
let return_expr_type = &return_expr_types[0];
108114
let return_expr_range = return_expr_ranges[0];
109-
let result = semantic_model.type_check(return_type, &return_expr_type);
115+
let result = semantic_model.type_check(check_type, &return_expr_type);
110116
if !result.is_ok() {
111117
add_type_check_diagnostic(
112118
context,

crates/emmylua_code_analysis/src/semantic/generic/instantiate_func_generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn instantiate_func_generic(
5050
&arg_types,
5151
&call_expr.get_root(),
5252
&mut substitutor,
53-
);
53+
)?;
5454

5555
if func.contain_self() {
5656
infer_self_type(db, cache, &call_expr, &mut substitutor)?;

0 commit comments

Comments
 (0)