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

Allow to omit commas in multiline function signature block #22021

Open
2 tasks
dadooda opened this issue Aug 10, 2024 · 5 comments
Open
2 tasks

Allow to omit commas in multiline function signature block #22021

dadooda opened this issue Aug 10, 2024 · 5 comments
Labels
Feature Request This issue is made to request a feature.

Comments

@dadooda
Copy link

dadooda commented Aug 10, 2024

Describe the feature

It's cool that Vlang lets us omit the comma when using multiline syntax in array enumeration and function calls. Like this:

// (1) ✅
greet('Mr.', 'Joe')

// (2) ✅
greet(
  'Mr.'
  'Joe'
)

At the same time, it's not yet possible to omit the comma in greet() definition (signature):

// (3) ✅
fn greet(salutation string, name string) {
  println('Hey, ${salutation} ${name}!')
}

// (4) ❌
fn greet(
  salutation string
  name string
) {
  println('Hey, ${salutation} ${name}!')
}

I'd propose example (4) above to be made possible.

Use Case

Comma omission in multiline enumerations looks good, feels good. And it's partially supported already. Let's make it consistently available in all parts of the language.

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

Environment details (OS name and version, etc.)

Ubuntu 18 under WSL.

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.

@dadooda dadooda added the Feature Request This issue is made to request a feature. label Aug 10, 2024
@JalonSolov
Copy link
Contributor

V seems to allow greet('Mr.' 'Joe') as well. I think that should actually be an error. It is working in V because V still sees it as 2 separate strings, but it shouldn't work, as there really should be a , separator between the parameters, whether they are on the same line or not.

For example, this works, too, and it looks really odd...

fn greet(i1 int, i2 int) {
  println('${i1} ${i2}')
}

greet(17 23)

@dadooda
Copy link
Author

dadooda commented Aug 10, 2024

For example, this works, too, and it looks really odd...

Oh yes, it does… The parser definitely needs some reinforcement…

@medvednikov
Copy link
Member

Good find, will fix.

I like no comma when there're newlines, that's why I implemented this way back:

arr := [
'foo'
'bar'
]

Many people are against this, and vfmt was changed to insert a ,.

I still think a comma shouldn't be needed here. Just like ; Looks cleaner this way.

@JalonSolov
Copy link
Contributor

As long as it's documented that either newline or comma works. But then what about OP's comment about function declarations? Shouldn't they work the same way, then?

As long as it doesn't work on same line without the comma.

@Wajinn
Copy link

Wajinn commented Aug 26, 2024

Just adding an opinion. Agree with the line of thinking that it should be consistent. So in reference to the examples that dadooda gave, if example 2 is allowed, then arguably so should example 4. Otherwise, don't allow both 2 and 4, and force the comma.

Many people are against this, and vfmt was changed to insert a ,.

Possibly the fear is people doing strange things or mistakes, like multiple blank lines in between. Thus the comma to make sure.

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

No branches or pull requests

4 participants