-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operator precedence is wrong when casted value is left-shifted in if/match expr #19978
Comments
Code generated: VV_LOCAL_SYMBOL void main__main(void) {
println(u8_str(((((u8)(1)) << 1) | 1)));
println(u8_str(((0 == (0))? ((((u8)(1)) << 1)) : (0))));
println(u8_str((true ? ((((u8)(1)) << 1)) : (0))));
} So it is not about precedence, but not taking care of the whole expression when parsing. |
a := 1
println(match 0 {
0 { u8(1) << 1 | a }
else { 0 }
}) generates VV_LOCAL_SYMBOL void main__main(void) {
int a = 1;
println(u8_str(((0 == (0))? ((((u8)(1)) << (1 | a))) : (0))));
} so it is about precedence |
Ah right. I've checked it with: fn main() {
println(if false {
u8(1) << 1 | 2
} else {
0
})
} Generates: |
I have the same problem, I handled it locally, but it still has problem in array fn test_test() {
mut arr := [u8(1), 9]
arr << 3
t := if true {
arr[0] << 1 | arr[1]
} else {
1
}
println(t) // print 0, should be 11
}
u8(id) is |
I found it radically difficult to solve this kind of problem: mut a := [0]
b := 1
c := match 0 {
0 {
a << 1 | 1 // compiler have to parse it as a << (1 | 1)
b << 1 | 1 // compiler have to parse it as (b << 1) | 1
}
else {
0
}
} This is completely context-sensitive. |
Yes, for Ident it is. But for the CastExpr treated here it is okay for now. |
Describe the bug
I'm so afraid of this bug that I can't even use any expression
Reproduction Steps
Expected Behavior
Current Behavior
u8(1) << (1 | 1)
is calculated instead (why?)Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.3 043ebb8
Environment details (OS name and version, etc.)
OS: Arch Linux
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: