V: optional multiple returns

Created on 30 Jan 2020  Â·  4Comments  Â·  Source: vlang/v

V version: V 0.1.24 ed55778
OS: macOS 10.15

What did you do?

failing compilation:

 33 fn kv(s string) ?(string, string) {
 34         kw := s.split_nth(':', 2)
 35         if kw.len != 2 {
 36                 return error('invalid token')
 37         }
 38         return kw[0].trim_space(), kw[1].trim_space()
 39 }

workaround

 33 fn kv(s string) (string, string) {
 34         kw := s.split_nth(':', 2)
 35         if kw.len != 2 {
 36                 return '', ''
 37         }
 38         return kw[0].trim_space(), kw[1].trim_space()
 39 }

What did you expect to see?

being able to use optional multiple returns

What did you see instead?

invalid syntax error with confusing message:

v build .
./suite.v:33:24: unexpected token `string`
   31| }
   32|
   33| fn kv(s string) ?(string, string) {
                              ^
   34|  kw := s.split_nth(':', 2)
   35|  if kw.len != 2 {
Bug

Most helpful comment

If its a known limitation it will be good to have a meaningful error message instead of a weird syntax one. But i think it should be supported

On 30 Jan 2020, at 02:15, joe-conigliaro notifications@github.com wrote:


Thanks @radare,
This is a know limitaiton as support for this was never added.
@medvednikov I think we discussed it a while back, if I remember correctly.
What are your thoughts about this?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

All 4 comments

Thanks @radare,
This is a know limitaiton as support for this was never added.
@medvednikov I think we discussed it a while back, if I remember correctly.
What are your thoughts about this?

If its a known limitation it will be good to have a meaningful error message instead of a weird syntax one. But i think it should be supported

On 30 Jan 2020, at 02:15, joe-conigliaro notifications@github.com wrote:


Thanks @radare,
This is a know limitaiton as support for this was never added.
@medvednikov I think we discussed it a while back, if I remember correctly.
What are your thoughts about this?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

@radare I have added optional support for multiple returns https://github.com/vlang/v/pull/3620

Thank you

On 1 Feb 2020, at 07:54, joe-conigliaro notifications@github.com wrote:


@radare I have added optional support for multiple returns, I will push soon

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oleg-kachan picture oleg-kachan  Â·  3Comments

XVilka picture XVilka  Â·  3Comments

clpo13 picture clpo13  Â·  3Comments

radare picture radare  Â·  3Comments

medvednikov picture medvednikov  Â·  3Comments