Subject: Re: bug#50781: 27.2; completing-read with a vector

From: Lars Ingebrigtsen <[email-masked]>
Date: Sat, 25 Sep 2021 04:15:12 +0200

Al Haji-Ali <[email-masked]> writes:

> I am not sure if `completing-read` is supposed to accept a vector but
> an error is not thrown on this usage (incidentally helpful uses
> `completing-read` in this way).
>
> However, starting from `emacs -Q` and executing the following code
>
> (completing-read "Test: " [A B C])
>
> works but then pressing <TAB> for auto-completion shows objects beside
> A, B and C.

The documentation here says:

COLLECTION can be a list of strings, an alist, an obarray or a hash table.

So using a vector isn't really supported, but works in some instances by
chance.

> On the other hand, executing
> (completing-read "Test: " [1 2 3])
> and then pressing <TAB> shows the error `(error "Bad data in guts of obarray")`

It interprets all vectors as obarrays, and an obarray is just a vector
of symbols.  But numbers aren't symbols, which is what it's complaining
about.

We could make `completing-read' iterate over all the elements in the
vector to see whether it's valid, and signal an error earlier, but it
would make common usages slower.

So I don't think there's an error in Emacs here -- feeding a
(non-obarray) vector to `completing-read' is not supported, and is an
error in the code that does it.  So I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no