dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.96k stars 4.03k forks source link

VB Editor changed VB keywords casing although they are used as literal strings in my code! #35028

Open VBAndCs opened 5 years ago

VBAndCs commented 5 years ago

Version Used: VS.NET 2019 Community

I had this Function in VB

    Private Function convVars(type As String) As String
        If type Is Nothing Then Return Nothing
        Dim t = type.Trim().ToLower()
        Select Case t
            Case "Byte", "SByte", "Short", "UShort", "Long", "ULong", "douple", "Decimal"
                Return t
            Case "Integer"
                Return "int"
            Case "UInteger"
                Return "uint"
            Case "Single"
                Return "float"
            Case Else
                Return type.Trim().Replace(
                    (" Byte", " Byte"), (" SBtye", " SByte"), (" Short", " Short"),
                    (" UShort", " UShort"), (" Long", " Long"), (" ULong", " ULong"),
                    (" Double", " douple"), (" Decimal", " Decimal"),
                    (" Integer", " int"), (" UInteger", " uint"), (" Single", " float"),
                    ("(Of ", LessThan), ("Of ", LessThan), (")", GreaterThan)
                )

        End Select

    End Function

You can notice the statement: Dim t = type.Trim().ToLower() Then I check the values of t using Select case Obviously, I wouldn't change to small case the compare with strings containing upper case letters! This code isn't what I wrote! The editor suddenly changed the case of all VB keywords although they are just quoted strings! This happened also in another function where I used the string "declare" but suddenly found it became "Declare"! Also I found a strange Then added after a string although there is no If nearby! The sudden failure of unit testes (that passed before) reveals all this! I had to repair all these editor mistakes, but I am afraid to happen again! I don't know what triggers this strange action. I had these codes running for days! This just happened in the past few minutes, and I have no reason to think about!

Note: It seems related to XML literals. I explained how to reproduce this in https://github.com/dotnet/roslyn/issues/35028#issuecomment-485212309

CyrusNajmabadi commented 5 years ago

The editor can have a sign that what it thinks as an xml literal is actually containing a full vb.net lines of code

I think that's what it does. The problem is that you have contents in your xml that actually look like code.

vatsalyaagrawal commented 4 years ago

Design review conclusion:

VBAndCs commented 4 years ago

@vatsalyaagrawal Thanks for your efforts. Please note that the problem is not related to string literals (I tested that as described in the discussions above) but related to XML literals that doesn't have a proper closing tag, So, your conclusion should apply to dirty areas in XML literals.

sharwell commented 4 years ago

@VBAndCs Thanks for the clarification. Yes, the same conclusion would apply to XML literals.

VBAndCs commented 3 years ago

This issue state is Complete in IDE: Design review since 31 Oct 2019, almost two years ago! I still face issues because of this bug, the most recent one is a few minutes ago! I work a lot with parsers and currently I am working on Small Visual Basic project, where the parser deals with vb keywords, so, any change in casing can corrupt the parser. Luckily I retried the source back from my repository on github. Please fix this bug.