-
Notifications
You must be signed in to change notification settings - Fork 222
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
VB -> C#: Null coalesce missing brackets #626
Comments
Should be a very straightforward fix. Let me know if you're interested in having a go and want some hints. |
Actually for the ternary operator parenthesis are added when needed, but not for the null-coalescing operator. I've added a test to describe the issue, but don't have a clue how to fix it. It would be nice to get some hints. |
Nice, always good to start with the test. OK, so the first thing is to figure out which syntax type the expression is. SharpLab has a nice syntax tree viewer: Then you'll usually find there's a "Visit" method for that syntax construct (in this case within the CSharp namespace since that's the target language) CodeConverter/CodeConverter/CSharp/ExpressionNodeVisitor.cs Lines 612 to 619 in 1bb96ee
So if you breakpoint that, your test should hit it You may notice that right below that method is the ternary case which you mentioned works, so see if you can make this one work using a similar mechanism. |
I applied the same mechanism as used for the ternary operator. That makes the test pass. I'm not sure what the purpose of |
In other words: would |
Yeah sounds right. I think it's a special case: within string interpolation, ternary statements need parentheses in c# to avoid a compile error. Should have really had a comment. Could write a test to check this works within string interpolation to be sure. |
Ah yes, just saw you did a test for it, nice |
Input code
Erroneous output
Expected output
Details
The text was updated successfully, but these errors were encountered: