Skip to content

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

Merged
merged 9 commits into from
Feb 25, 2020
Merged

Support default args #159

merged 9 commits into from
Feb 25, 2020

Conversation

LumaKernel
Copy link

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

(function (F a))
(function (G a))
(function (F) (a))
(function (G) (a))
Copy link
Member

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?

Copy link
Author

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)))

Copy link
Author

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) . ...))

Copy link
Author

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.

Copy link
Author

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
Copy link
Member

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

Copy link
Author

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

@mattn
Copy link
Member

mattn commented Feb 25, 2020

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
Copy link
Member

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

@tyru tyru merged commit 50d8ac4 into vim-jp:master Feb 25, 2020
@tyru
Copy link
Member

tyru commented Feb 25, 2020

Thanks!

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.

Handle default arguments with functions
3 participants