Skip to content

Commit ad91f6a

Browse files
committed
fix #480
1 parent 03817bb commit ad91f6a

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/flow/bind_analyze/stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ pub fn bind_if_stat(binder: &mut FlowBinder, if_stat: LuaIfStat, current: FlowId
307307
let block_id = bind_block(binder, else_block, else_label);
308308
binder.add_antecedent(post_if_label, block_id);
309309
}
310+
} else {
311+
binder.add_antecedent(post_if_label, else_label);
310312
}
311313

312314
finish_flow_label(binder, post_if_label, else_label)

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,24 @@ end
802802
let res_desc = ws.humanize_type(res);
803803
assert_eq!(res_desc, "(string[]|string)");
804804
}
805+
806+
#[test]
807+
fn test_issue_480() {
808+
let mut ws = VirtualWorkspace::new_with_init_std_lib();
809+
810+
ws.check_code_for(
811+
DiagnosticCode::UnnecessaryAssert,
812+
r#"
813+
--- @param a integer?
814+
--- @param c boolean
815+
function foo(a, c)
816+
if c then
817+
a = 1
818+
end
819+
820+
assert(a)
821+
end
822+
"#,
823+
);
824+
}
805825
}

crates/emmylua_code_analysis/src/semantic/infer/narrow/condition_flow/binary_flow.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,7 @@ fn maybe_type_guard_binary(
156156
return Ok(ResultTypeOrContinue::Continue);
157157
};
158158

159-
let LuaExpr::NameExpr(name_expr) = arg else {
160-
return Ok(ResultTypeOrContinue::Continue);
161-
};
162-
163-
let Some(maybe_var_ref_id) =
164-
get_var_expr_var_ref_id(db, cache, LuaExpr::NameExpr(name_expr.clone()))
165-
else {
159+
let Some(maybe_var_ref_id) = get_var_expr_var_ref_id(db, cache, arg) else {
166160
// If we cannot find a reference declaration ID, we cannot narrow it
167161
return Ok(ResultTypeOrContinue::Continue);
168162
};

0 commit comments

Comments
 (0)