Skip to content

Commit c996acf

Browse files
committed
diagnostic: fix AssignTypeMismatch
1 parent 43290a2 commit c996acf

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ mod tests {
4242
));
4343
}
4444

45+
#[test]
46+
fn test_3() {
47+
let mut ws = VirtualWorkspace::new();
48+
assert!(ws.check_code_for_namespace(
49+
DiagnosticCode::AssignTypeMismatch,
50+
r#"
51+
---@param s string
52+
---@param i? integer
53+
---@param j? integer
54+
---@param lax? boolean
55+
---@return integer?
56+
---@return integer? errpos
57+
---@nodiscard
58+
local function get_len(s, i, j, lax) end
59+
60+
local len = 0
61+
---@diagnostic disable-next-line: need-check-nil
62+
len = len + get_len("", 1, 1, true)
63+
"#
64+
));
65+
}
66+
4567
#[test]
4668
fn test_issue_193() {
4769
let mut ws = VirtualWorkspace::new();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ fn infer_binary_expr_add(db: &DbIndex, left: LuaType, right: LuaType) -> InferRe
162162
}
163163
};
164164
}
165+
match (left.is_nil(), right.is_nil()) {
166+
(true, false) => return Some(right),
167+
(false, true) => return Some(left),
168+
_ => {}
169+
}
165170

166171
infer_binary_custom_operator(db, &left, &right, LuaOperatorMetaMethod::Add)
167172
}

0 commit comments

Comments
 (0)