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

Possibly wrong pattern match in VirtualizingStackPanel.GetControl #15955

Closed
jnyrup opened this issue Jun 8, 2024 · 3 comments · Fixed by #16005
Closed

Possibly wrong pattern match in VirtualizingStackPanel.GetControl #15955

jnyrup opened this issue Jun 8, 2024 · 3 comments · Fixed by #16005

Comments

@jnyrup
Copy link

jnyrup commented Jun 8, 2024

Describe the bug

In C# the pattern x is not A or B is interpreted as x is (not A) or B and not x is not (A or B).

I was grep'ing my local git repositories for code that matched and stumbled upon

fromControl is null && direction is not NavigationDirection.First or NavigationDirection.Last)

So this code is not checking whether direction is "neither First nor Last".
As Last is covered by not First Roslyn even lowers this to != First.
As such this looks like a bug to me

image

SharpLab

To Reproduce

I found this by analyzing the code and didn't write any code I don't know and haven't looked into if this potential bug can be hit.

Expected behavior

No response

Avalonia version

master

OS

No response

Additional context

No response

@jnyrup jnyrup added the bug label Jun 8, 2024
@maxkatz6
Copy link
Member

It is wrong, you are correct.
Whole condition should be changed from

if (count == 0 || 
-                fromControl is null && direction is not NavigationDirection.First or NavigationDirection.Last)
+               (fromControl is null && direction != NavigationDirection.First && direction != NavigationDirection.Last)

@timunie
Copy link
Contributor

timunie commented Jun 11, 2024

@jnyrup maybe you can file a PR with the fix? 🙏 thx

@jnyrup
Copy link
Author

jnyrup commented Jun 11, 2024

@jnyrup maybe you can file a PR with the fix? 🙏 thx

Unfortunately I don't have the time to do this.
I'll pass it on to other contributors.

@nil4 nil4 mentioned this issue Jun 12, 2024
3 tasks
github-merge-queue bot pushed a commit that referenced this issue Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants