Subject: Re: bug#24641: 26.0.50; let-alist: Incorrect byte-compile warning about unused lexical variable

From: [email-masked]
Date: Sat, 08 Oct 2016 09:09:52 -0400

retitle 24641 let-alist redundantly binds variables already bound by nested let-alist calls
severity 24641 minor
tags 24641 confirmed
quit

Philipp <[email-masked]> writes:

> $ cat /tmp/letalist.el 
> ;; -*- lexical-binding: t; -*-
> (print
>  (let-alist '((outer . ((inner . value))))
>    (let-alist .outer .inner)))
>    
> $ emacs -Q -batch -f batch-byte-compile /tmp/letalist.el 
>
> In toplevel form:
> /tmp/letalist.el:2:1:Warning: Unused lexical variable ‘\.inner’
>
> This warning is incorrect because '.inner' is used in the inner
> let-alist form.

The byte compiler warning correct, the problem is in let-alist: both the
outer and inner let-alist calls let-bind '.inner'.  Here is the
macroexpansion:

(let
    ((#1=#:alist
      '((outer
         (inner . value)))))
  (let
      ((\.outer
        (cdr
         (assq 'outer #1#)))
       (\.inner ; <------------ this one is unused
        (cdr
         (assq 'inner #1#))))
    (let
        ((#2=#:alist \.outer))
      (let
          ((\.inner
            (cdr
             (assq 'inner #2#))))
        \.inner))))