Skip to content

Commit 309c218

Browse files
committed
Fix test
1 parent 906a97f commit 309c218

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod test {
9191
fn test_issue_360() {
9292
let mut ws = VirtualWorkspace::new();
9393

94-
assert!(ws.check_code_for(
94+
assert!(!ws.check_code_for(
9595
DiagnosticCode::RedundantParameter,
9696
r#"
9797
---@alias buz number

crates/emmylua_code_analysis/src/semantic/overload_resolve/resolve_signature_by_args.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ pub fn resolve_signature_by_args(
181181
best_match_result = func.clone();
182182
}
183183

184+
if match_result == ParamMatchResult::NotMatch {
185+
need_resolve_funcs[i] = None;
186+
continue;
187+
}
188+
184189
if match_result > ParamMatchResult::AnyMatch {
185190
if param_index + 1 == func.get_params().len() {
186191
return Ok(func.clone());
@@ -193,6 +198,98 @@ pub fn resolve_signature_by_args(
193198
}
194199
}
195200

201+
let mut rest_need_resolve_funcs = need_resolve_funcs
202+
.iter()
203+
.filter_map(|it| it.clone())
204+
.map(|it| Some(it))
205+
.collect::<Vec<_>>();
206+
207+
match rest_need_resolve_funcs.len() {
208+
0 => return Ok(best_match_result),
209+
1 => return Ok(rest_need_resolve_funcs[0].clone().unwrap()),
210+
_ => {}
211+
}
212+
213+
let start_param_index = exp_len;
214+
let mut max_param_len = 0;
215+
for opt_func in &rest_need_resolve_funcs {
216+
if let Some(func) = opt_func {
217+
let param_len = func.get_params().len();
218+
if param_len > max_param_len {
219+
max_param_len = param_len;
220+
}
221+
}
222+
}
223+
224+
let rest_len = rest_need_resolve_funcs.len();
225+
for param_index in start_param_index..max_param_len {
226+
let mut current_match_result = ParamMatchResult::NotMatch;
227+
for i in 0..rest_len {
228+
let opt_func = &rest_need_resolve_funcs[i];
229+
if opt_func.is_none() {
230+
continue;
231+
}
232+
let func = opt_func.as_ref().unwrap();
233+
let param_len = func.get_params().len();
234+
let colon_define = func.is_colon_define();
235+
let mut param_index = param_index;
236+
match (colon_define, is_colon_call) {
237+
(true, false) => {
238+
if param_index == 0 {
239+
continue;
240+
}
241+
param_index -= 1;
242+
}
243+
(false, true) => {
244+
param_index += 1;
245+
}
246+
_ => {}
247+
}
248+
let param_type = if param_index < param_len {
249+
let param_info = func.get_params().get(param_index);
250+
param_info
251+
.map(|it| it.1.clone().unwrap_or(LuaType::Any))
252+
.unwrap_or(LuaType::Any)
253+
} else if let Some(last_param_info) = func.get_params().last() {
254+
if last_param_info.0 == "..." {
255+
last_param_info.1.clone().unwrap_or(LuaType::Any)
256+
} else {
257+
return Ok(func.clone());
258+
}
259+
} else {
260+
return Ok(func.clone());
261+
};
262+
263+
let match_result = if param_type.is_any() {
264+
ParamMatchResult::AnyMatch
265+
} else if param_type.is_nullable() {
266+
ParamMatchResult::TypeMatch
267+
} else {
268+
ParamMatchResult::NotMatch
269+
};
270+
271+
if match_result > current_match_result {
272+
current_match_result = match_result;
273+
best_match_result = func.clone();
274+
}
275+
276+
if match_result == ParamMatchResult::NotMatch {
277+
rest_need_resolve_funcs[i] = None;
278+
continue;
279+
}
280+
281+
if match_result >= ParamMatchResult::AnyMatch {
282+
if param_index + 1 == func.get_params().len() {
283+
return Ok(func.clone());
284+
}
285+
}
286+
}
287+
288+
if current_match_result == ParamMatchResult::NotMatch {
289+
break;
290+
}
291+
}
292+
196293
Ok(best_match_result)
197294
}
198295

0 commit comments

Comments
 (0)