[vim/vim] Vim9: cannot surround ternary operator with parentheses (#8462)

38 views
Skip to first unread message

lacygoill

unread,
Jun 26, 2021, 2:51:13 PM6/26/21
to vim/vim, Subscribed

Describe the bug

In Vim9 script, we cannot surround a ternary operator with parentheses.

To Reproduce

Run this shell command:

vim -Nu NONE +'vim9 echo (a == 0 ? 0 : 0)'

E15 is raised:

E15: Invalid expression: "= 0 ? 0 : 0)"

Expected behavior

No error is raised.

Environment

  • Vim version: 8.2 Included patches: 1-3056
  • OS: Ubuntu 20.04.2 LTS
  • Terminal: XTerm(353)

Additional context

Regression introduced in 8.2.3056.


The previous code is useless. Here, is a more useful one:

const FLAG2ARG: dict<string> = {
    S: '<script>',
    b: '<buffer>',
    e: '<expr>',
    n: '<nowait>',
    s: '<silent>',
    u: '<unique>',
}
def MapMeta(
    key: string,
    rhs: string,
    mode: string,
    flags: string
)
    exe (mode != '!' ? mode : '') .. (flags =~ 'r' ? 'map' : 'noremap') .. (mode == '!' ? '!' : '')
        .. ' ' .. MapArguments(flags)
        .. ' ' .. '<m-' .. key .. '>'
        .. ' ' .. rhs
enddef
def MapArguments(flags: string): string
    return split(flags, '\zs')
        ->map((_, v: string): string => get(FLAG2ARG, v, ''))
        ->join()
enddef
defcompile


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

lacygoill

unread,
Jun 26, 2021, 3:04:32 PM6/26/21
to vim/vim, Subscribed

No error is raised.

Actually, an error would be raised even if the issue was fixed, because a is undefined. Here is a new MWE:

vim -Nu NONE +'vim9 var a = 0 | vim9 echo (a == 0 ? 0 : 0)'

Bram Moolenaar

unread,
Jun 26, 2021, 3:52:38 PM6/26/21
to vim/vim, Subscribed

Closed #8462 via 015cf10.

lacygoill

unread,
Jun 26, 2021, 4:02:54 PM6/26/21
to vim/vim, Subscribed

The issue was fixed for the == comparison operator, but it persists for =~:

vim -Nu NONE +'vim9 var a = "" | vim9 echo (a =~ "" ? 0 : 0)'
E15: Invalid expression: "~ "" ? 0 : 0)"
Reply all
Reply to author
Forward
0 new messages