Skip to content

Commit 9ed2402

Browse files
authored
Merge pull request #412 from xuhuanzy/fix_405
fix #405
2 parents 7b1e29b + 87fbbb2 commit 9ed2402

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/flow/var_analyze/broadcast_up.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::sync::Arc;
22

33
use emmylua_parser::{
4-
BinaryOperator, LuaAst, LuaAstNode, LuaBinaryExpr, LuaExpr, LuaLiteralToken, UnaryOperator,
4+
BinaryOperator, LuaAst, LuaAstNode, LuaBinaryExpr, LuaExpr, LuaForStat, LuaLiteralToken,
5+
UnaryOperator,
56
};
67
use smol_str::SmolStr;
78

@@ -184,6 +185,17 @@ pub fn broadcast_up(
184185
);
185186
}
186187
}
188+
UnaryOperator::OpLen => {
189+
if let Some(for_stat) = unary_expr.get_parent::<LuaForStat>() {
190+
broadcast_inside_condition_block(
191+
db,
192+
var_trace,
193+
trace_info.with_type_assertion(TypeAssertion::Narrow(LuaType::Table)),
194+
for_stat.get_block()?,
195+
false,
196+
);
197+
}
198+
}
187199
_ => {}
188200
}
189201
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,24 @@ end
560560
"#,
561561
));
562562
}
563+
564+
#[test]
565+
fn test_issue_405() {
566+
let mut ws = VirtualWorkspace::new();
567+
568+
ws.def(
569+
r#"
570+
---@type false|fun(...)[]?
571+
local calls
572+
573+
for i = 1, #calls do
574+
a = calls
575+
end
576+
"#,
577+
);
578+
579+
let a = ws.expr_ty("a");
580+
let a_expected = ws.ty("fun(...)[]");
581+
assert_eq!(a, a_expected);
582+
}
563583
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,23 @@ mod test {
1414
"#
1515
));
1616
}
17+
18+
#[test]
19+
fn test_issue_405() {
20+
let mut ws = VirtualWorkspace::new();
21+
let mut emmyrc = ws.analysis.emmyrc.as_ref().clone();
22+
emmyrc.strict.array_index = false;
23+
ws.analysis.update_config(emmyrc.into());
24+
assert!(ws.check_code_for(
25+
DiagnosticCode::NeedCheckNil,
26+
r#"
27+
---@type false|fun(...)[]?
28+
local calls
29+
30+
for i = 1, #calls do
31+
calls[i](...)
32+
end
33+
"#
34+
));
35+
}
1736
}

0 commit comments

Comments
 (0)