Skip to content

Commit 056ec9d

Browse files
committed
fix(flow): reuse ordered return analysis for loop exits
Replace the old missing-return special cases with the same ordered block walker used for inferred returns. This avoids false MissingReturn diagnostics for functions that return from truthy while/repeat loops, keeps break and repeat-until flow consistent across inference and diagnostics, and adds regressions for closure returns, diagnostics, and module exports.
1 parent 420edbc commit 056ec9d

10 files changed

Lines changed: 631 additions & 227 deletions

File tree

crates/emmylua_code_analysis/src/compilation/analyzer/lua/closure.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
infer_expr,
1515
};
1616

17-
use super::{LuaAnalyzer, LuaReturnPoint, func_body::analyze_func_body_returns};
17+
use super::{LuaAnalyzer, LuaReturnPoint, func_body::analyze_func_body_returns_with};
1818

1919
pub fn analyze_closure(analyzer: &mut LuaAnalyzer, closure: LuaClosureExpr) -> Option<()> {
2020
let signature_id = LuaSignatureId::from_closure(analyzer.file_id, &closure);
@@ -136,7 +136,12 @@ fn analyze_return(
136136
}
137137
};
138138

139-
let return_points = analyze_func_body_returns(block);
139+
let return_points = analyze_func_body_returns_with(block, |condition_expr| {
140+
analyzer
141+
.infer_expr(&condition_expr)
142+
.map(|condition_type| condition_type.is_always_truthy())
143+
.unwrap_or(false)
144+
});
140145
let returns = match analyze_return_point(
141146
analyzer.db,
142147
analyzer
@@ -189,7 +194,12 @@ fn analyze_lambda_returns(
189194
.get_args()
190195
.position(|arg| arg.get_position() == pos)?;
191196
let block = closure.get_block()?;
192-
let return_points = analyze_func_body_returns(block);
197+
let return_points = analyze_func_body_returns_with(block, |condition_expr| {
198+
analyzer
199+
.infer_expr(&condition_expr)
200+
.map(|condition_type| condition_type.is_always_truthy())
201+
.unwrap_or(false)
202+
});
193203
let unresolved = UnResolveClosureReturn {
194204
file_id: analyzer.file_id,
195205
signature_id: *signature_id,

0 commit comments

Comments
 (0)