Skip to content

Commit f78ce16

Browse files
committed
Fix #376
1 parent 482341b commit f78ce16

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod out_of_order;
1818
mod overload_field;
1919
mod overload_test;
2020
mod pcall_test;
21+
mod return_unwrap_test;
2122
mod static_cal_cmp;
2223
mod syntax_error_test;
2324
mod tuple_test;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#[cfg(test)]
2+
mod test {
3+
use crate::{LuaType, VirtualWorkspace};
4+
5+
#[test]
6+
fn test_issue_376() {
7+
let mut ws = VirtualWorkspace::new();
8+
9+
ws.def(
10+
r#"
11+
---@return any
12+
function get() end
13+
14+
local sub = get()
15+
16+
if sub and type(sub) == 'table' then
17+
-- sub is nil - wrong
18+
a = sub
19+
end
20+
"#,
21+
);
22+
23+
let a_ty = ws.expr_ty("a");
24+
let expected = LuaType::Table;
25+
assert_eq!(a_ty, expected);
26+
}
27+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn unwrapp_return_type(
369369
call_expr: LuaCallExpr,
370370
) -> InferResult {
371371
match &return_type {
372-
LuaType::Table | LuaType::Any | LuaType::Unknown => {
372+
LuaType::Table => {
373373
let id = InFiled {
374374
file_id: cache.get_file_id(),
375375
value: call_expr.get_range(),

0 commit comments

Comments
 (0)