You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code, the match is covering all cases but compiling still trigger an error saying an else is required.
Reproduction Steps
fnperlin_grad_2d(hash int, x f64, y f64) f64 {
returnmatch hash &0xF {
0x0 { x + y }
0x1 { -x + y }
0x2 { x - y }
0x3 { -x - y }
0x4 { x }
0x5 { -x }
0x6 { x }
0x7 { -x }
0x8 { y }
0x9 { -y }
0xA { y }
0xB { -y }
0xC { y + x }
0xD { -y }
0xE { y - x }
0xF { -y }
}
}
fnmain() {
nb:=perlin_grad_2d(5, 2.3, 5.4)
println(nb)
}
Expected Behavior
The code should instead compile correctly.
Current Behavior
It trigger this error :
C:\Users\loicp\Documents\GitHub\vsl>v run test.v
test.v:2:9: error: match must be exhaustive (add `else {}` at the end)
1 | fn perlin_grad_2d(hash int, x f64, y f64) f64 {
2 | return match hash & 0xF {
| ~~~~~~~~~~~~~~~~~~
3 | 0x0 { x + y }
4 | 0x1 { -x + y }
Possible Solution
I think compiler check the type of hash instead of hash & 0xF to determine if all cases are covered.
Here V is requesting an else branch that will have dead code. I think is difficult for the compiler to consider all potential cases to prevent dead code. Recalls me this issue.
Describe the bug
In the following code, the match is covering all cases but compiling still trigger an error saying an else is required.
Reproduction Steps
Expected Behavior
The code should instead compile correctly.
Current Behavior
It trigger this error :
Possible Solution
I think compiler check the type of
hash
instead ofhash & 0xF
to determine if all cases are covered.Additional Information/Context
No response
V version
V 0.4.10 86536e4
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: