Skip to content

Commit da35c85

Browse files
committed
Fix #258
Fix #266
1 parent 7a9d355 commit da35c85

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

crates/emmylua_code_analysis/src/compilation/test/and_or_test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,21 @@ mod test {
5757
"Union(LuaUnionType { types: [Nil, IntegerConst(2)] })"
5858
);
5959
}
60+
61+
#[test]
62+
fn test_issue_258() {
63+
let mut ws = VirtualWorkspace::new();
64+
65+
ws.def(
66+
r#"
67+
local a --- @type string|nil
68+
local b --- @type string|nil
69+
c = a or b
70+
"#,
71+
);
72+
73+
let c = ws.expr_ty("c");
74+
let c_desc = ws.humanize_type(c);
75+
assert_eq!(c_desc, "(string|nil)");
76+
}
6077
}

crates/emmylua_code_analysis/src/compilation/test/flow.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,23 @@ end
300300
"#
301301
));
302302
}
303+
304+
#[test]
305+
fn test_issue_266() {
306+
let mut ws = VirtualWorkspace::new();
307+
308+
assert!(ws.check_code_for(DiagnosticCode::AssignTypeMismatch, r#"
309+
--- @return string
310+
function baz() end
311+
312+
local a
313+
a = baz() -- a has type nil but should be string
314+
d = a
315+
"#));
316+
317+
let d = ws.expr_ty("d");
318+
let d_desc = ws.humanize_type(d);
319+
assert_eq!(d_desc, "string");
320+
}
321+
303322
}

0 commit comments

Comments
 (0)