Skip to content
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 varargs for ProcLiteral #5102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

makenowjust
Copy link
Contributor

Add specs for parser, ASTNode#to_s, formatter and codegen also.

Now we can use ... inside ProcLiteral arguments, for example:

foo = ->(...) do
  p :foo
end

It is import to resolve TODO in src/xml/error.cr (

# TODO: use va_start and va_end to
) because va_start and va_end work correctly only inside function marked as varargs.

Add parser, ASTNode#to_s, formatter and codegen specs also

Now we can use `...` inside ProcLiteral arguments, for example:

```crystal
foo = ->(...) do
  p :foo
end
```

It is import to resolve TODO in `src/xml/error.cr`
(https://github.com/crystal-lang/crystal/blob/2637f83644c27a909b332b6a0a1cd0cecb283851/src/xml/error.cr#L23).
@makenowjust makenowjust force-pushed the feature/crystal/proc-literal-varargs branch from 9db543f to 0e7391e Compare October 11, 2017 12:02
@makenowjust
Copy link
Contributor Author

NOTE: We cannot call such a ProcLiteral as variadic like ->(...) { }.call(1, 2, 3). It is same as fun:

fun foo(...)
  p 1
end

foo(1, 2, 3) # this line cannot compile

I think it is correct behavior because varargs is the feature only for C integration.

Copy link
Contributor

@ysbaddaden ysbaddaden left a comment

Choose a reason for hiding this comment

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

I definitely welcome this! It would help to simplify JNI bindings, for example.

Maybe use variadic instead of varargs thought, unless we already use the varargs naming?

@bew
Copy link
Contributor

bew commented Oct 11, 2017

@makenowjust I don't understand why it should not be possible to call a ProcLiteral or a fun with variadic args from crystal?

@makenowjust
Copy link
Contributor Author

@bew No technically reason for fun, I implemented this but omit from this PR. However, to call a ProcLiteral with variadic is hard because current crystal type system cannot keep variadic information in ProcType.

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

Successfully merging this pull request may close these issues.

None yet

5 participants