Bug Report T419773
Visible to All Users

'Smart semicolon' feature in CodeRush for Roslyn incorrectly moves semicolons for lambda expressions

created 9 years ago

I have code much like this in a Visual Studio test project (so it has a reference to Microsoft.QualityTools.Testing.Fakes), with a fakes assembly generated for System.Data:

enum DbPicStatus { UnknownPic, InvalidPic, ValidPic }
IDataReader Demo(DbPicStatus a_dbPicStatus)
{
    int readCalled = 0;
    return new System.Data.Fakes.StubIDataReader
    {
        GetOrdinalString = (a_colName) =>
        {
            if (readCalled != 1) { throw new InvalidOperationException("Read did not return true."); }
            if (a_colName.ToUpper() == "IMPB") { return 1; }
            throw new InvalidDataException($"Column {a_colName} is unknown.");
        },
        GetStringInt32 = (a_idx) =>
        {
            if (a_idx != 1) { throw new ArgumentException($"Unknown column {a_idx}.", nameof(a_idx)); }
            switch (a_dbPicStatus)
            {
                case DbPicStatus.ValidPic: return "IMPB";
                case DbPicStatus.InvalidPic: return "INVALID_IMPB";
                default:
                    Assert.Fail($"Unknown PIC status {a_dbPicStatus}.");
                    break/* Try to add a semicolon to this line, either before or after this comment. */
            }
            return null;
        },
        Read = () => a_dbPicStatus == DbPicStatus.UnknownPic ? false : ++readCalled == 1,
    };/* Insertion point incorrectly moves to the beginning of this comment. */
}

The testing tools and fakes assemblies are not necessary for demonstrating this issue. When you paste this into a class with the necessary references and usings, there will be two errors. One on the nameof expression, and one at the end of the break statement. If you don't have those references and usings, there will be more errors, but the reproduction will still work just fine:
With Smart semicolon turned on, try to add a semicolon after the break statement.

The expected behavior is that a semicolon appears. The actual behavior is that the insertion point is moved right after the semicolon on the second-to-last line, as indicated by the comment on that line.

Comments (1)
AE AE
Alex Eg (DevExpress) 8 years ago

    Hi Dale,
    Thank you for the code snippet. I have reproduced the issue, and we are working on it. We will update this ticket once we make any progress.

    Answers approved by DevExpress Support

    created 8 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.