File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
crates/emmylua_code_analysis/src
semantic/infer/infer_call Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ mod out_of_order;
1818mod overload_field;
1919mod overload_test;
2020mod pcall_test;
21+ mod return_unwrap_test;
2122mod static_cal_cmp;
2223mod syntax_error_test;
2324mod tuple_test;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 ( ) ,
You can’t perform that action at this time.
0 commit comments