Bug Report T600878
Visible to All Users

Code Style - Applying the optional parentheses code style works incorrectly with nullable member access expressions

created 7 years ago (modified 7 years ago)

Hello,

Currently the code cleaning utility will change the following, valid C# code:

C#
public override string ToString() { if ((_Numbers?.Length).GetValueOrDefault(0) == 0) return "?"; return string.Join(".", Numbers); }

… to this invalid code:

C#
public override string ToString() { if (_Numbers?.Length.GetValueOrDefault(0) == 0) return "?"; return string.Join(".", Numbers); }

The parenthesis around _Numbers?.Length gets removed, causing the compiler to detect a syntax error. Truth is: parenthesis shouldn't have been removed in the first place.

Please advise. Thanks.

EDIT :

Some additional details: this seems to occur only if the following cleanup rule is set: "Apply 'optional parenthesis' style to explicitly declare precedence of expressions". Checking it off solves the issue.

Of course it doesn't change the fact that CodeRush should be smart enough to detect if it can safely remove parenthesis or not. :)

Comments (1)
DevExpress Support Team 7 years ago

    Hi David,

    Thank you for reporting this issue.
    I have managed to reproduce this problem locally. We are working on a solution. You will be notified when a fix is ready.

    Answers approved by DevExpress Support

    created 7 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.