v
v copied to clipboard
Cgen `error: cannot convert 'struct _option_int' to 'int'`
Describe the bug
See code: https://play.vlang.io/p/ab17c4b2cc
interface IFoo {
age ?int
get(param ?int) ?int
}
struct Foo {
age ?int
}
fn (f Foo) get(param ?int) ?int {
return param or { f.age }
}
foo := IFoo(Foo{age: 100})
println(foo.get(100))
Expected Behavior
No error
Current Behavior
Cgen error
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
fn (f Foo) get(param ?int) ?int {
return param or { f.age? }
}
Adding ? to the end of f.age seems to work.
fn (f Foo) get(param ?int) ?int { return param or { f.age? } }
Adding ? to the end of f.age seems to work.
Yes, but it must throws error without unwrapping the option.
f.age is supposed to be of type ?int, so it should be able to return directly
f.age is supposed to be of type ?int, so it should be able to return directly
Not exactly. or block
must resolve to unwrapped expected type, not to another option one. This is as V planned it.
f.age is supposed to be of type ?int, so it should be able to return directly
Not exactly.
or block
must resolve to unwrapped expected type, not to another option one. This is as V planned it.
ok,I got it.