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 spreadding an array after and before explicit function parameters #22394

Open
2 tasks
heyimtcn opened this issue Oct 2, 2024 · 1 comment
Open
2 tasks
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.

Comments

@heyimtcn
Copy link
Contributor

heyimtcn commented Oct 2, 2024

Describe the feature

allow this:

const foo = [3,4,5]

fn bar(baz ...int) {
	dump(baz)
}

fn main() {
	bar(1,2,...foo)
	bar(...foo,6,7)
}

Use Case

needed by eptx on discord (https://discord.com/channels/592103645835821068/592294828432424960/1290834184905953403)

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.4.8 2b546c4

Environment details (OS name and version, etc.)

V full version: V 0.4.8 18eee34.2b546c4
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 16 cpus, 64bit, little endian,

vexe: C:\Users\nicof\Desktop\v\v.exe
vexe mtime: 2024-10-02 19:33:15

vroot: OK, value: C:\Users\nicof\Desktop\v
VMODULES: OK, value: C:\Users\nicof.vmodules
VTMP: OK, value: C:\Users\nicof\AppData\Local\Temp\v_0

Git version: git version 2.45.2.windows.1
Git vroot status: weekly.2024.34-260-g2b546c4f
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc: N/A

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@heyimtcn heyimtcn added the Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. label Oct 2, 2024
@islonely
Copy link
Contributor

I don't think this should be allowed. Just stumbling across this in some code 9 times out of 10 you would probable assume the 1, 2, is separate function parameters from ...foo. It would be difficult to read and understand what's happening without knowing in advanced that the underlying function uses variable number of arguments. But also, what situation can you not already do this:

mut foo := [1, 2]
foo << [3, 4, 5]
bar(...foo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants