roslynator
roslynator copied to clipboard
RCS1032 False positive targeting "F(G<A,B>(7));" grammar ambiguity
Product and Version Used: Roslynator 2.9.0, Visual Studio 2019 16.4.4
Steps to Reproduce:
Demo on SharpLab
Details: icsharpcode/ILSpy#1959 (F(G<A,B>(7)); grammar ambiguity on MSDN)
Actual Behavior:
RCS1032 Remove redundant parentheses. shown for (num < num2)
Expected Behavior: The parentheses are necessary to avoid ambiguity.
This is a rare case that will be hard (or impossible) to detect during code analysis. I think it is reasonable to suppress this diagnostic one by one.
Example:
#pragma warning disable RCS1032
#pragma warning restore RCS1032
My solution for ILSpy actually works on the syntax tree; essentially trying to re-interpret the existing expression syntax nodes as if they were types. A similar approach should be possible here.