mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-03 00:14:21 +01:00
Fix evaluation of ISNULL/NOTNULL in OR expressions
Previously, the `jump_if_condition_is_true` flag was not respected. As a result, for expressions like <`ISNULL`/`NOTNULL`> `OR` <rhs>, the <rhs> expression was evaluated even when the left-hand side was true, and its value was incorrectly used as the final result.
This commit is contained in:
@@ -362,18 +362,32 @@ pub fn translate_condition_expr(
|
||||
ast::Expr::NotNull(expr) => {
|
||||
let cur_reg = program.alloc_register();
|
||||
translate_expr(program, Some(referenced_tables), expr, cur_reg, resolver)?;
|
||||
program.emit_insn(Insn::IsNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_false,
|
||||
});
|
||||
if condition_metadata.jump_if_condition_is_true {
|
||||
program.emit_insn(Insn::NotNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_true,
|
||||
});
|
||||
} else {
|
||||
program.emit_insn(Insn::IsNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_false,
|
||||
});
|
||||
}
|
||||
}
|
||||
ast::Expr::IsNull(expr) => {
|
||||
let cur_reg = program.alloc_register();
|
||||
translate_expr(program, Some(referenced_tables), expr, cur_reg, resolver)?;
|
||||
program.emit_insn(Insn::NotNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_false,
|
||||
});
|
||||
if condition_metadata.jump_if_condition_is_true {
|
||||
program.emit_insn(Insn::IsNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_true,
|
||||
});
|
||||
} else {
|
||||
program.emit_insn(Insn::NotNull {
|
||||
reg: cur_reg,
|
||||
target_pc: condition_metadata.jump_target_when_false,
|
||||
});
|
||||
}
|
||||
}
|
||||
ast::Expr::Unary(_, _) => {
|
||||
// This is an inefficient implementation for op::NOT, because translate_expr() will emit an Insn::Not,
|
||||
|
||||
Reference in New Issue
Block a user