roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

RCS1032 False positive targeting "F(G<A,B>(7));" grammar ambiguity

Open sgkoishi opened this issue 5 years ago • 2 comments
trafficstars

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.

sgkoishi avatar Apr 01 '20 20:04 sgkoishi

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

josefpihrt avatar Apr 08 '20 18:04 josefpihrt

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.

dgrunwald avatar May 01 '20 16:05 dgrunwald