From 14d7a9b9c12a9279618680e1efaf840df942b137 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 20 Nov 2023 13:40:58 -0700 Subject: [PATCH] fix dif:vars_remove_goal/2 (#2175), untabify forms.rs to appease format check --- src/forms.rs | 10 +++++----- src/lib/dif.pl | 12 +++++++----- src/tests/dif.pl | 7 +++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/forms.rs b/src/forms.rs index 3a2b743f2..d18d41f15 100644 --- a/src/forms.rs +++ b/src/forms.rs @@ -744,11 +744,11 @@ impl Number { Number::Float(f) => Number::Float(OrderedFloat(f.signum())), _ => { if self.is_positive() { - if self.is_zero() { - Number::Fixnum(Fixnum::build_with(0)) - } else { - Number::Fixnum(Fixnum::build_with(1)) - } + if self.is_zero() { + Number::Fixnum(Fixnum::build_with(0)) + } else { + Number::Fixnum(Fixnum::build_with(1)) + } } else if self.is_negative() { Number::Fixnum(Fixnum::build_with(-1)) } else { diff --git a/src/lib/dif.pl b/src/lib/dif.pl index 8efb42710..c344e1d75 100644 --- a/src/lib/dif.pl +++ b/src/lib/dif.pl @@ -33,11 +33,13 @@ vars_remove_goal([], _). vars_remove_goal([Var|Vars], Goal0) :- - get_atts(Var, +dif(Goals0)), - remove_goal(Goals0, Goal0, Goals), - ( Goals = [] -> - put_atts(Var, -dif(_)) - ; put_atts(Var, +dif(Goals)) + ( get_atts(Var, +dif(Goals0)) -> + remove_goal(Goals0, Goal0, Goals), + ( Goals = [] -> + put_atts(Var, -dif(_)) + ; put_atts(Var, +dif(Goals)) + ) + ; true ), vars_remove_goal(Vars, Goal0). diff --git a/src/tests/dif.pl b/src/tests/dif.pl index 752f14054..1696c64a3 100644 --- a/src/tests/dif.pl +++ b/src/tests/dif.pl @@ -207,6 +207,13 @@ \+ E=[] )). +% https://github.com/mthom/scryer-prolog/issues/2175 +test("scryer-prolog#2175",( + dif(A,B), + A=C*[], + A=[]*D*B,D=[] +)). + main :- findall(test(Name, Goal), test(Name, Goal), Tests), run_tests(Tests, Failed),