[vim/vim] Vim9: a few inconsistencies with expressions at start of line (Issue #10434)

16 views
Skip to first unread message

lacygoill

unread,
May 16, 2022, 2:13:49 PM5/16/22
to vim/vim, Subscribed

Consider these snippets:

vim9script
123
E1050: Colon required before a range: 123
vim9script
eval 123
E1207: Expression without an effect: 123

Should the first one give E1207 just like the second one?


Consider these 2 other snippets:

vim9script
'string'
no error
vim9script
eval 'string'
no error

To be consistent with the previous ones, shouldn't they give this error:

E1207: Expression without an effect: 'string'

Finally, consider these 2 snippets:

vim9script
var n = 123
$'{n}'->setline(1)
E1050: Colon required before a range: $'{n}'
vim9script
def Func()
    var n = 123
    $'{n}'->setline(1)
enddef
Func()
E476: Invalid command: $'{n}'

First, the errors are different between the script level and the body a :def function. Should they be made the same?

Second, could we recognize $ as the start of an interpolated string when followed by a quote? It would be more consistent with how non-interpolated strings can be used at the start of a line and followed by a method call:

vim9script
'123'->setline(1)
123
vim9script
def Func()
    '123'->setline(1)
enddef
Func()
123

Note that as a workaround, we can use parens:

vim9script
var n = 123
($'{n}')->setline(1)
123
vim9script
def Func()
    var n = 123
    ($'{n}')->setline(1)
enddef
Func()
123


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

Bram Moolenaar

unread,
May 17, 2022, 7:46:09 AM5/17/22
to vim/vim, Subscribed

Closed #10434 via 0d03263.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/10434/issue_event/6623750340@github.com>

Bram Moolenaar

unread,
May 17, 2022, 7:46:58 AM5/17/22
to vim/vim, Subscribed


> Consider these snippets:
> ```vim

> vim9script
> 123
> ```
> E1050: Colon required before a range: 123
> ```vim

> vim9script
> eval 123
> ```
> E1207: Expression without an effect: 123
>
> Should the first one give `E1207` just like the second one?

The current behavior is correct. In legacy script "123" would move the
cursor to line 123, thus we can assume that this was the intention.
You don't accidentally type "eval", but evaluating "123" makes no sense,
thus that error is appropriate.


> Consider these 2 other snippets:
> ```vim
> vim9script
> 'string'
> ```
> no error
> ```vim

> vim9script
> eval 'string'
> ```
> no error
>
> To be consistent with the previous ones, shouldn't they give this error:
>
> E1207: Expression without an effect: 'string'

Yeah, we can also check for a string. Note that this error is just to
catch simple mistakes, if you do "eval 1 + 2" there won't be an error.


> Finally, consider these 2 snippets:
> ```vim

> vim9script
> var n = 123
> $'{n}'->setline(1)
> ```
> E1050: Colon required before a range: $'{n}'
> ```vim

> vim9script
> def Func()
> var n = 123
> $'{n}'->setline(1)
> enddef
> Func()
> ```
> E476: Invalid command: $'{n}'
>
> First, the errors are different between the script level and the body
> a `:def` function. Should they be made the same?
>
> Second, could we recognize `$` as the start of an interpolated string
> when followed by a quote? It would be more consistent with how
> non-interpolated strings can be used at the start of a line and
> followed by a method call:
> ```vim

> vim9script
> '123'->setline(1)
> ```
> 123
> ```vim

> vim9script
> def Func()
> '123'->setline(1)
> enddef
> Func()
> ```
> 123
>
> Note that as a workaround, we can use parens:
> ```vim

> vim9script
> var n = 123
> ($'{n}')->setline(1)
> ```
> 123
> ```vim

> vim9script
> def Func()
> var n = 123
> ($'{n}')->setline(1)
> enddef
> Func()
> ```
> 123

I don't think $' and $" are every valid in a range, thus we could
recognize them as an interpolated string.

--
hundred-and-one symptoms of being an internet addict:
218. Your spouse hands you a gift wrapped magnet with your PC's name
on it and you accuse him or her of genocide.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/10434/1128768802@github.com>

Reply all
Reply to author
Forward
0 new messages