OR in combination with AndAlso may wrongly translate
ursvogel opened this issue · 4 comments
VB.Net input code
If (tb.Job = Job Or tb.Key = Job) AndAlso tb.ID = ID Then
Erroneous output
if (tb.Job == Job || tb.Key == Job && tb.ID == ID)
Expected output
if ((tb.Job == Job || tb.Key == Job) && tb.ID == ID)
Details
- Product in use: VS extension
- Version in use: [9.2.5] - 2024-01-31
- No
Thanks, I'm surprised to see that, definitely needs fixing!
Hmm, I just tried to convert this on website
Imports System
Public Class C
Public Class Dto
Public Job As Double
Public ID As Integer
Public Key as Double
End Class
Public Sub M(tb as Dto)
Dim Job As Double = ""
Dim ID As Integer = 1
If (tb.Job = Job Or tb.Key = Job) AndAlso tb.ID = ID Then
System.Console.WriteLine("1")
End If
End Sub
End Class
and the result is
if (tb.Job == Job | tb.Key == Job && tb.ID == ID)
Works as expected to me. |
has higher precedence than &&
so simplifier skiped brackets.
I had actually expected bitwise to take precedence yeah. I did try comparing outputs for the whole truth table and found that it does behave differently, but only tried it in vb. So maybe c# is different.
C sharp operator precedence prioritises the pipe operator: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/#operator-precedence