From 084968c08a81ec8e3ac6428e1c42a787adef290c Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Thu, 29 Jan 2026 17:34:48 +0800 Subject: [PATCH] fix: implication operator (->) --- nix-js/src/codegen.rs | 2 +- nix-js/tests/operators.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/nix-js/src/codegen.rs b/nix-js/src/codegen.rs index 478ad42..d2b168c 100644 --- a/nix-js/src/codegen.rs +++ b/nix-js/src/codegen.rs @@ -351,7 +351,7 @@ impl Compile for BinOp { Impl => { code!( 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 => { diff --git a/nix-js/tests/operators.rs b/nix-js/tests/operators.rs index 4c2e45f..d0f4f2b 100644 --- a/nix-js/tests/operators.rs +++ b/nix-js/tests/operators.rs @@ -117,3 +117,28 @@ fn select_with_default_nested_lazy() { fn select_with_default_fallback() { 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)); +}