Skip to content

Commit 5094ac1

Browse files
committed
Fix #374
1 parent d7c114d commit 5094ac1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ return t
822822
"#
823823
));
824824
}
825+
825826
#[test]
826827
fn test_issue_393() {
827828
let mut ws = VirtualWorkspace::new();
@@ -840,4 +841,21 @@ return t
840841
"#
841842
));
842843
}
844+
845+
#[test]
846+
fn test_issue_374() {
847+
let mut ws = VirtualWorkspace::new();
848+
assert!(ws.check_code_for(
849+
DiagnosticCode::AssignTypeMismatch,
850+
r#"
851+
--- @param x? integer
852+
--- @return integer?
853+
--- @overload fun(): integer
854+
function bar(x) end
855+
856+
--- @type integer
857+
local _ = bar() -- - error cannot assign `integer?` to `integer`
858+
"#
859+
));
860+
}
843861
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ fn resolve_signature_by_args(
8686
jump_param = 0;
8787
};
8888

89+
// 如果在不计算可空参数的情况下, 参数数量完全匹配, 则认为其权重更高
90+
if params.len() == fake_expr_len {
91+
total_weight += params.len() as i32 + 1;
92+
}
93+
8994
// 冒号定义且冒号调用
9095
if is_colon_call && func.is_colon_define() {
9196
total_weight += 100;

0 commit comments

Comments
 (0)