[vim/vim] fix: typename() returns wrong type for lists/dicts/tuples with shared references (PR #19492)

5 views
Skip to first unread message

h_east

unread,
Feb 23, 2026, 4:25:55 PM (yesterday) Feb 23
to vim/vim, Subscribed

Fixes: #19490

Problem

typename() incorrectly returned list for the member type when a container
held multiple references to the same inner object. For example:

echo [[" "]]->repeat(3)->typename()   " returned list<list<any>>, expected list<list<string>>

repeat() makes all elements point to the same inner list/dict/tuple object
(shallow copy via copy_tv()). During type inference, list_typval2type(),
dict_typval2type(), and tuple_typval2type() use a copyID to guard against
infinite recursion on circular references. However, they never cleared the
copyID after finishing, so when the same object was encountered again as a
sibling element (a shared reference, not a circular one), it was mistakenly
treated as a circular reference and t_list_any / t_dict_any / t_tuple_any was
returned.

Solution

Reset lv_copyID / dv_copyID / tv_copyID to 0 after all members have been
processed in each of the three functions. The circular reference guard still
works correctly because the copyID is set before processing members and only
cleared after — so any re-entrant call on the same object during its own
traversal is still detected and short-circuits with t_*_any.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19492

Commit Summary

  • c1d9e68 fix: typename() returns wrong type for lists/dicts/tuples with shared references

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19492@github.com>

Mao-Yining

unread,
Feb 23, 2026, 7:14:35 PM (yesterday) Feb 23
to vim/vim, Subscribed
mao-yining left a comment (vim/vim#19492)

The document didn’t describe how to deal with a list within a list. Would it be more sensible to use copy() or deepcopy(), or just add a note to the documentation?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19492/c3948097392@github.com>

Christian Brabandt

unread,
4:29 PM (6 hours ago) 4:29 PM
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19492)

thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19492/c3954837898@github.com>

Christian Brabandt

unread,
4:29 PM (6 hours ago) 4:29 PM
to vim/vim, Subscribed

Closed #19492 via b1d4b03.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19492/issue_event/23048405718@github.com>

Reply all
Reply to author
Forward
0 new messages