"Variable not introduced in all branches" message in library(pprint)

library(pprint) causes compiler_warning(unbalanced_var(V)) message from print_term_2/2 (line 128) when I use style_check(+var_branches). The problem seems to be in this section of code – if I change Out to Out2 in the second if-then-else, the warning message goes away.

    (   option(fullstop(true), Options)
    ->  option(output(Out), Options),
        put_char(Out, '.')
    ;   true
    ),
    (   option(nl(true), Options)
    ->  option(output(Out), Options),  % change Out to Out2 here
        nl(Out)                        % and here to remove warning message
    ;   true
    ).

(I use swipl --on_warnings=status, so this breaks my code unless I surround the use_module with style_check(-var_branches).)

1 Like

This warning always gave me too many false positives. Still, not reusing the same variable is IMO better style here. Pushed a fix.

1 Like

Good to know. I have seen a few of these that I just gave up on.