Subject: bug#73117: 30.0.90; Imenu missing entries when flattening by group

From: Troy Brown <[email-masked]>
Date: Sat, 7 Sep 2024 21:41:43 -0400

This issue appears to be similar to the issue reported in 70846, but
this is specifically regarding when Imenu is configured to flatten
into "groups" (as opposed to "annotation" as was reported there).
When "imenu-flatten" is set to "group", I see an issue where nested
entries, with the same name but belonging to different parents, aren't
all displayed.

I've included an example below (based on the example menu
configuration described in 70846).  This example cycles through
flattening based on "index", "group" and "annotation" with the example
menu configuration.

For "prefix" and "annotation" configurations, it appears to work
correctly, as pressing "M-<down>" when the menu prompt is displayed, I
can see both entries identified in the "*Completions*" buffer.

However, when I do this with "imenu-flatten" set to "group" and press
"M-<down>" to display the completions window, the window indicates "2
possible completions" but only one is actually displayed and
selectable (i.e., the one under "Bar").  The menu entry "Foo" under
"Baz" is not displayed at all and it appears there is no way to select
it.

```
;; begin
(progn
  (require 'imenu)
  (dolist (flatten '(prefix group annotation))
    (setq imenu-flatten flatten)

    (imenu-choose-buffer-index (format "(%s) Index item: " flatten)
                               `(("Bar" . (("Foo" . ,(point-min-marker))))
                                 ("Baz" . (("Foo" . ,(point-max-marker))))))))
;; end
```