-
Notifications
You must be signed in to change notification settings - Fork 25
Support default args #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support default args #159
Conversation
Compile result is changed.
test/test_xxx_funcarg_last_comma.ok
Outdated
(function (F a)) | ||
(function (G a)) | ||
(function (F) (a)) | ||
(function (G) (a)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder that this is breaking AST for function node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
from
(function (F) (a))
to
(function (F (a)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
function! F(a, b = 2)
: (function (F (a) (b 2)))
function! F(a = 1 + 1, b = 2)
: (function (F (a (+ 1 1)) (b 2)))
function! F(a = 1, b = 2, ...)
: (function (F (a 1) (b 2) . ...))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, realized that to omit parenthesis if there's no default args resolves around backward compatibility. And that seems preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
function! F(a, b = 2)
: (function (F a (b 2)))
@@ -0,0 +1,2 @@ | |||
function Foo(abc=1, xyz) | |||
endfunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add test for:
function X(foo=1+2)
return a:foo
endfunction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test/test_funcarg_default.vim
Seems good to me. Pass to another look. |
@@ -2,6 +2,9 @@ | |||
function s:foo(a, b, ...) | |||
return 0 | |||
endfunction | |||
function s:bar(a = 1, b = 2, ...) | |||
return 0 | |||
endfunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this too.
function s:baz(a, b = 2, ...)
return 0
endfunction
Thanks! |
Fix #154
Is there any spec about Compiler AST ? I broke it a little around
:function
.MEMO: https://github.com/vim/vim/blob/v8.2.0246/src/userfunc.c#L199-L236