v
v copied to clipboard
Forgetting dereferencing enum reference fails
V version: V 0.2.2 273655e.e9d7ff7 OS: Microsoft Windows 10 Pro v19041 64 bit
What did you do?
enum SomeType {
a
}
fn f(t &SomeType) ?int {
return match
t // note the missing asterisk
{
.a {
panic('This does not happen!')
3
}
}
}
fn main() {
t := SomeType.a
f(&t)?
assert false // should not happen, but does
}
What did you expect to see?
A compiler error: missing '*' dereferencing in match statement
. Or at least auto-dereferencing matching the .a
in the example.
What did you see instead?
A failed match, as well as Assertion failed
in the above example.
This seems to be fully correct behavior. V does auto-dereferencing everywhere on its own. Also manual dereferencing is considered unsafe and in the future shall be allowed only in unsafe{}
blocks (if not already true - I didn't check it in all cases).
Did you not read the example? It says a
is not taken. I.e. no match. And no warning.
Hm, I've reacted to your rather incorrect expactation in What did you expect to see? :wink:
But yes, the match shall succeed. I didn't realize the Assertion failed
in your text doesn't refer to some panic-related assertion but to your assert false
.
@spytheman what do you think? a checker error here? @medvednikov
Yes, a checker error.