Subject: Re: bug#75997: (ice-9 match): warning: unused variable `failure'

From: Tomas Volf <[email-masked]>
Date: Fri, 28 Feb 2025 02:33:32 +0100

Ludovic Courtès <[email-masked]> writes:

> Tomas Volf <[email-masked]> skribis:
>
>> (lambda (expr)
>>   (let* ((v expr)
>>          (failure
>>            (lambda ()
>>              ((@@ (ice-9 match) throw)
>>               'match-error
>>               "match"
>>               "no matching pattern"
>>               v)
>>              #f)))
>>     #f))
>
> Hi!  Currently the unused-variable warning pass is unable to determine
> that ‘failure’ was introduced by expanding a macro and thus that no
> warning should be emitted.
>
> It’s always been this way and I don’t know of a clear way to fix it.

I cannot really help regarding the general case.  However in this
specific it would likely suffice to tweak the expansion to

--8<---------------cut here---------------start------------->8---
(lambda (expr)
  (let* ((v expr)
         (failure
           (lambda ()
             ((@@ (ice-9 match) throw)
              'match-error
              "match"
              "no matching pattern"
              v)
             #f)))
    failure
    #f))
--8<---------------cut here---------------end--------------->8---

Should have zero performance impact due to optimizations (I would hope),
but feels somewhat ugly.

Tomas

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.