modus icon indicating copy to clipboard operation
modus copied to clipboard

Warning for when an "arbitrary" rule is chosen?

Open maowtm opened this issue 2 years ago • 3 comments

Just spent 3 hour on a simple mistake caused by an accidentally unbounded variable.

maowtm avatar Mar 05 '22 02:03 maowtm

Can you elaborate on this?

thevirtuoso1973 avatar Mar 05 '22 13:03 thevirtuoso1973

Basically I had a config predicate that defined some config corresponding to variants, like:

config("default", "make all").
config("32bit", "make 32bit").

etc...

And I use it like this:

redis(version, variant) :-
  ...
  config(variant, make_cmd),
  ...
  run(make_cmd).

However, there was a special case for when variant = "alpine", so I copy-pasted the definition for redis and added this:

redis(version, "alpine") :-
  ...
  config(variant, make_cmd),
  ...
  run(make_cmd).

I thought it would be alright to just replace the "variant" variable with "alpine", and I thought I have replaced all the "variant" variable, but it turns out I forgot to replace the "variant" in the config line, so the result is that it arbitrarily chose a make_cmd, and because it is quite deep inside a merge I did not notice that, so was wondering why things won't compile...

maowtm avatar Mar 05 '22 13:03 maowtm

I was thinking about a warning when there are multiple valid choices for a predicate. This would also prevent mistake like

foo(bar) :- (bar = "1"; bar = "2"), do_things_specific_for_1_and_2.
foo(bar) :- bar != "1", do_things_for_anything_else. # did not cover the case where bar = "2".

When we add some kind of cost-based selection later maybe we could limit this warning to just logic predicates...

maowtm avatar Mar 05 '22 13:03 maowtm