Skip to content
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

Strange result combining range and ternary operation #33109

Closed
bhalonen opened this issue Aug 29, 2019 · 4 comments
Closed

Strange result combining range and ternary operation #33109

bhalonen opened this issue Aug 29, 2019 · 4 comments

Comments

@bhalonen
Copy link

1: -1 == 1 ? 3 : 2
results in the integer 2.
as does
1:-1 == 1 ? 3 : 2
Similar to #23599.

@bhalonen
Copy link
Author

The range 1:-1 is being compared to 1, which gives 2.

@StefanKarpinski
Copy link
Sponsor Member

What's the issue? Looks correct to me.

@bhalonen
Copy link
Author

I expected it to form a range, for full context it was.
a[1: -1 == 1 ? 3 : 2]
which gives the element a[2]
Perhaps this only confused me.

@StefanKarpinski
Copy link
Sponsor Member

The range : operator has higher precedence than the ternary ?: operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants