v icon indicating copy to clipboard operation
v copied to clipboard

Forgetting dereferencing enum reference fails

Open highfestiva opened this issue 3 years ago • 4 comments

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.

highfestiva avatar May 08 '21 00:05 highfestiva

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

dumblob avatar May 11 '21 21:05 dumblob

Did you not read the example? It says a is not taken. I.e. no match. And no warning.

highfestiva avatar May 12 '21 06:05 highfestiva

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.

dumblob avatar May 12 '21 07:05 dumblob

@spytheman what do you think? a checker error here? @medvednikov

felipensp avatar Mar 23 '23 20:03 felipensp

Yes, a checker error.

medvednikov avatar May 27 '23 01:05 medvednikov