Spurious "Local variable $Var appears only once" warning with closure

I think it’s a bug, so in case of I’m writing it here so that there is a trace of it somewhere.

When a variable appears only in a closure, Dialog will report the following warning:

Possible typo: Local variable $Var only appears once.

For example, the following will cause a warning on (with closure):

(without closure)
    ($X = @without-closure)
    (if) (word $X) (then)
        $X
    (endif)

%% Same as `(without closure)` but using a closure.
(with closure)
    ($Clos = {
        ($X = @closure)
        (if) (word $X) (then)
            $X
        (endif)
    })
    %% Uncomment the following to remove the warning.
    %% (if) (fail) (then) $X (endif)
    (query $Clos)

(program entry point)
    (without closure)
    (with closure)

You can remove the warning by using the variable outside the closure. (But it’ll be unbound, so you can just put it inside an (if) that always fails for example.)

1 Like