Skip to content

Switch expression precedence? #53490

Discussion options

You must be logged in to vote

This is somewhat unexpected to me, is this the intended behavior?

Yes. This is the intended behavior. switch has higher precedence than %, so your code is effectively parsed as if it ws:

        value % (8 switch {
            0 => value,
            _ => ((value / 8) + 1) * 8 
        });

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@CyrusNajmabadi
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by AlgorithmsAreCool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants