v icon indicating copy to clipboard operation
v copied to clipboard

Cgen error: `could not generate string method 'void_str' for type 'void'`

Open i582 opened this issue 2 years ago • 2 comments

Describe the bug

See code: https://play.vlang.io/?query=481ebca0e6

fn foo() ? {
	return none, 100
}

fn main() {
	println(foo())
}

Expected Behavior

No cgen error

Current Behavior

Cgen error:

cgen error: could not generate string method `void_str` for type `void`

Reproduction Steps

Run code above

Possible Solution

No response

Additional Information/Context

No response

V version

0.3.3

Environment details (OS name and version, etc.)

Playground

i582 avatar Mar 02 '23 17:03 i582

I think that it is already fixed by the other issue.

felipensp avatar Mar 05 '23 17:03 felipensp

The playground needs to be updated. It still gives this message. Latest V on desktop says

foo.v:2:9: error: can only return `none` from an Option-only return function
    1 | fn foo() ? {
    2 |     return none, 100
      |            ~~~~
    3 | }
    4 |

However, if you fix the code to only return none, you do still get the error message...

fn foo() ? {
        return none
}

fn main() {
        println(foo())
}

says

cgen error: could not generate string method `void_str` for type `void`

JalonSolov avatar Mar 05 '23 18:03 JalonSolov