Skip to content

Commit 82079f1

Browse files
committed
fix check MissingReturn
1 parent 63ac688 commit 82079f1

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ fn check_missing_return(
8282
if let Some(ty) = variadic.get_type(i) {
8383
if ty.is_optional() {
8484
real_min_len -= 1;
85-
} else if ty.is_tpl() {
86-
real_min_len -= 1;
8785
} else {
8886
break;
8987
}

crates/emmylua_code_analysis/src/diagnostic/test/check_return_count_test.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,4 +508,20 @@ mod tests {
508508
"#,
509509
));
510510
}
511+
512+
#[test]
513+
fn test_missing_return_1() {
514+
let mut ws = VirtualWorkspace::new_with_init_std_lib();
515+
assert!(!ws.check_code_for(
516+
DiagnosticCode::MissingReturn,
517+
r#"
518+
---@generic T
519+
---@param field T
520+
---@return T
521+
---@return T
522+
local function test(field)
523+
end
524+
"#,
525+
));
526+
}
511527
}

crates/emmylua_code_analysis/src/semantic/infer/mod.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use smol_str::SmolStr;
2929

3030
use crate::{
3131
db_index::{DbIndex, LuaOperator, LuaOperatorMetaMethod, LuaSignatureId, LuaType},
32-
InFiled, LuaMemberKey, VariadicType,
32+
InFiled, InferGuard, LuaMemberKey, VariadicType,
3333
};
3434

3535
use super::{member::infer_raw_member_type, CacheEntry, CacheKey, LuaInferCache};
@@ -276,28 +276,31 @@ pub fn infer_bind_value_type(
276276
let is_colon_call = call_expr.is_colon_call();
277277

278278
let expr_type = infer_expr(db, cache, call_expr.get_prefix_expr()?).ok()?;
279-
match expr_type {
280-
LuaType::Signature(signature_id) => {
281-
let signature = db.get_signature_index().get(&signature_id)?;
282-
match (signature.is_colon_define, is_colon_call) {
283-
(true, false) => {
284-
param_pos += 1;
285-
}
286-
(false, true) => {
287-
if param_pos == 0 {
288-
return None;
289-
}
290-
param_pos -= 1;
291-
}
292-
_ => {}
279+
let func_type = infer_call_expr_func(
280+
db,
281+
cache,
282+
call_expr,
283+
expr_type.clone(),
284+
&mut InferGuard::new(),
285+
None,
286+
)
287+
.ok()?;
288+
289+
match (func_type.is_colon_define(), is_colon_call) {
290+
(true, false) => {
291+
if param_pos == 0 {
292+
return None;
293293
}
294-
let param_info = signature.get_param_info_by_id(param_pos)?;
295-
return Some(param_info.type_ref.clone());
294+
param_pos -= 1;
295+
}
296+
(false, true) => {
297+
param_pos += 1;
296298
}
297299
_ => {}
298300
}
299301

300-
return None;
302+
let param_info = func_type.get_params().get(param_pos)?;
303+
return param_info.1.clone();
301304
}
302305
_ => None,
303306
};

0 commit comments

Comments
 (0)