Skip to content

Fix E728 in fzf#vim#colors() when called with a spec dict#1611

Open
MenkeTechnologies wants to merge 1 commit intojunegunn:masterfrom
MenkeTechnologies:fix-colors-dict-arg
Open

Fix E728 in fzf#vim#colors() when called with a spec dict#1611
MenkeTechnologies wants to merge 1 commit intojunegunn:masterfrom
MenkeTechnologies:fix-colors-dict-arg

Conversation

@MenkeTechnologies
Copy link
Copy Markdown

Problem

fzf#vim#colors() throws E728: Using a Dictionary as a Number when called with a spec dict as the first argument:

command! -bang Colors call fzf#vim#colors({'left': '20', 'options': '--reverse' }, <bang>0)

Line 614 does if !a:1 assuming a:1 is always a number, but the documented API is fzf#vim#colors([spec dict], [fullscreen bool]).

Fix

Add a type check before the boolean test, matching how s:fzf() already handles the same varargs pattern:

if a:0 && type(a:1) != s:TYPE.dict && !a:1

Fixes #1610

The public API for fzf#vim#colors() accepts ([spec dict], [fullscreen bool]),
but `if !a:1` on line 614 assumed a:1 is always a number. When a:1 is a
dictionary (e.g. from a custom :Colors command override), Vim throws
E728: Using a Dictionary as a Number.

Add type check before the boolean test, matching how s:fzf() already
handles the same varargs pattern.

Fixes junegunn#1610
Comment thread autoload/fzf/vim.vim
\}

if !a:1 " We can't set up IPC in fullscreen mode in Vim
if a:0 && type(a:1) != s:TYPE.dict && !a:1 " We can't set up IPC in fullscreen mode in Vim
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the function can take at most 2 arguments, the fullscreen flag may not be a:1 but a:2.

What do you think?

Suggested change
if a:0 && type(a:1) != s:TYPE.dict && !a:1 " We can't set up IPC in fullscreen mode in Vim
let fullscreen = a:0 && type(a:000[-1]) != s:TYPE.dict && a:000[-1]
if !fullscreen " We can't set up IPC in fullscreen mode in Vim

Test cases:

call fzf#vim#colors()
call fzf#vim#colors(0)
call fzf#vim#colors(1)
call fzf#vim#colors({})
call fzf#vim#colors({}, 0)
call fzf#vim#colors({}, 1)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks resilient enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E728 in fzf#vim#colors() when first arg is a dictionary

2 participants