[m-rev.] diff: Fix value of maybe_string option when negated.

Peter Wang novalazy at gmail.com
Tue Nov 8 16:04:15 AEDT 2022


library/getopt.m:
library/getopt_io.m:
    Fix bug where a negation option (--no-foo) would set the value of a
    maybe_string option to maybe_int(no) instead of maybe_string(no)
    in the option table.

diff --git a/library/getopt.m b/library/getopt.m
index 56c398142..710e39972 100644
--- a/library/getopt.m
+++ b/library/getopt.m
@@ -1176,7 +1176,7 @@ record_negated_option(OptionTable, Flag, OptName, MaybeError, !OptionValues) :-
                 OV = ov_maybe_int(Flag, OptName, maybe.no)
             ;
                 OptionData = maybe_string(_),
-                OV = ov_maybe_int(Flag, OptName, maybe.no)
+                OV = ov_maybe_string(Flag, OptName, maybe.no)
             ;
                 OptionData = accumulating(_),
                 OV = ov_accumulating_reset(Flag, OptName)
diff --git a/library/getopt_io.m b/library/getopt_io.m
index 2ac1572d9..9ff2422db 100644
--- a/library/getopt_io.m
+++ b/library/getopt_io.m
@@ -1176,7 +1176,7 @@ record_negated_option(OptionTable, Flag, OptName, MaybeError, !OptionValues) :-
                 OV = ov_maybe_int(Flag, OptName, maybe.no)
             ;
                 OptionData = maybe_string(_),
-                OV = ov_maybe_int(Flag, OptName, maybe.no)
+                OV = ov_maybe_string(Flag, OptName, maybe.no)
             ;
                 OptionData = accumulating(_),
                 OV = ov_accumulating_reset(Flag, OptName)
-- 
2.38.0



More information about the reviews mailing list