use emmylua_parser::LuaExpr;
use crate::{DbIndex, LuaType, TypeOps, semantic::infer::narrow::narrow_false_or_nil};
pub fn special_and_rule(
db: &DbIndex,
left_type: &LuaType,
right_type: &LuaType,
_left_expr: LuaExpr,
right_expr: LuaExpr,
) -> Option<LuaType> {
match right_expr {
LuaExpr::TableExpr(_) | LuaExpr::LiteralExpr(_) => {
let falsy_part = narrow_false_or_nil(db, left_type.clone());
if !falsy_part.is_never() && !left_type.is_always_falsy() {
return Some(TypeOps::Union.apply(db, &falsy_part, right_type));
}
}
_ => {}
}
None
}
pub fn infer_binary_expr_and(
db: &DbIndex,
left: LuaType,
right: LuaType,
) -> crate::semantic::infer::InferResult {
if left.is_always_falsy() {
return Ok(left);
} else if left.is_always_truthy() {
return Ok(right);
}
Ok(TypeOps::Union.apply(db, &narrow_false_or_nil(db, left), &right))
}