-
-
Notifications
You must be signed in to change notification settings - Fork 168
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 splat for varargs #1352
Comments
This is correct, as the compiler currently works but as an enhancement, this could be made to work in the general case, which will also increase the usefulness of the splat. |
This should be completely supported now. |
Sorry,no,it doesn't work with the latest c3c.Error: Splat may not be used with raw varargs if the length is not known. |
Just tested this, got the same error as LukyGuyLucky. The length should be know since i was using a fixed array, unless that is not the length it is referring to. |
module test;
extern fn void test(...);
fn void main()
{
int[2] y;
test(...y);
} This fails? |
If you do: extern fn void test(...);
fn void main()
{
int[] y = { 1, 2 };
test(...y);
} Then this will fail, as you are splatting a runtime slice into a raw vararg. However, this will succeed: extern fn void test(...);
fn void main()
{
int[] y = { 1, 2 };
test(...y[:2]);
} Because then the compiler will know the length. |
I thought |
|
I've improved the error message now though, and enabled: fn void test2(int a, int b) { }
fn void main()
{
int[2] x = { 1, 2 };
test2(...x);
} |
Didn't know about the [*] notation. With the new message and the improvement above this looks pretty solid, i'm eager to test it. |
@lerno Can confirm in the latest that this is working: fn void test2(int a, int b) {
io::printfn("a = %s, b = %s", a, b); // a = 5, b = 22
}
fn void main()
{
int[*] x = { 5, 22 };
test2(...x);
} Adding three values errors correctly: Adding one value errors correctly: |
Thank you! |
In the case of the string::tformat function, it accepts a variable number of arguments to pass to the format string. Would be nice to be able to unpack an array when calling it, for example:
Currently, i get this error when trying: Error: Splat may not be used with raw varargs. Trying to cast the parts array to any[] also doesn't seem to work.
The text was updated successfully, but these errors were encountered: