fix: implication operator (->)

This commit is contained in:
2026-01-29 17:34:48 +08:00
parent 058ef44259
commit 084968c08a
2 changed files with 26 additions and 1 deletions

View File

@@ -351,7 +351,7 @@ impl<Ctx: CodegenContext> Compile<Ctx> for BinOp {
Impl => { Impl => {
code!( code!(
buf, ctx; buf, ctx;
"Nix.withContext(\"while evaluating the || operator\"," self.span ",()=>(Nix.forceBool(" lhs ")||Nix.forceBool(" rhs ")))" "Nix.withContext(\"while evaluating the -> operator\"," self.span ",()=>(!Nix.forceBool(" lhs ")||Nix.forceBool(" rhs ")))"
); );
} }
PipeL => { PipeL => {

View File

@@ -117,3 +117,28 @@ fn select_with_default_nested_lazy() {
fn select_with_default_fallback() { fn select_with_default_fallback() {
assert_eq!(eval("{ a = 1; }.b or 999"), Value::Int(999)); assert_eq!(eval("{ a = 1; }.b or 999"), Value::Int(999));
} }
#[test]
fn implication_false_false() {
assert_eq!(eval("false -> false"), Value::Bool(true));
}
#[test]
fn implication_false_true() {
assert_eq!(eval("false -> true"), Value::Bool(true));
}
#[test]
fn implication_true_false() {
assert_eq!(eval("true -> false"), Value::Bool(false));
}
#[test]
fn implication_true_true() {
assert_eq!(eval("true -> true"), Value::Bool(true));
}
#[test]
fn implication_short_circuit() {
assert_eq!(eval("false -> (1 / 0)"), Value::Bool(true));
}