Removing parentheses seems to break pointer casting in C#

I've found a situation where if I follow the R# suggestion to remove redundant parentheses, it can break compilation.

 

Specifically, this occurs when I cast one pointer to another pointer type, dereference the pointer, and then cast it to some other type all in the same line.

 

Example:

MyClass myObject = (MyClass) (*(int*) myPointer);

 

R# suggests I get rid of the parentheses wrapping the dereference, which converts the line to this:

MyClass myObject = (MyClass) *(int*) myPointer;

 

However, I guess this causes the compiler to interpret the line as a multiplication of (MyClass) and (int*)myPointer, which breaks compilation.

 

Edit:

Playing with this a little more showed that the pointer cast is not necessary to trigger this issue.  

MyClass myObject = (MyClass) (*myPointer);

R# will have the same suggestion here, and following it will cause the same problem.

 

I've uploaded a toy project that demonstrates this issue via the web form as ParenthesesTest.zip.

 

R# version is 2017.3.4

VS version is 14.0.25431.1

0
4 comments

Hello!

 

Thank you for contacting us.

Please try the latest ReSharper 2018,1 EAP build and check if the problem is reproduced - https://www.jetbrains.com/resharper/eap/.

Thank you.

0
Avatar
Permanently deleted user

Hi Angelina,

 

Thanks for the reply.  I updated to 2018.1, and the issue was reproducible in the project I uploaded.  Please let me know if you need any other information.

0

Hello Robert!

 

Sorry for misleading you. The issue still persists in the latest versions.

I've filed correspondent issue - https://youtrack.jetbrains.com/issue/RSRP-469095.

Please feel free to comment or vote for it.

Thank you.

0
Avatar
Permanently deleted user

 Not a problem. Thanks Angelina!

0

Please sign in to leave a comment.