File tree Expand file tree Collapse file tree
Tests/TestData/SelfVerifyingTests/VBToCS Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -659,6 +659,12 @@ public override async Task<CSharpSyntaxNode> VisitUnaryExpression(VBasic.Syntax.
659659 if ( kind == SyntaxKind . LogicalNotExpression && await NegateAndSimplifyOrNullAsync ( node , expr ) is { } simpleNegation ) {
660660 return AsBool ( node , simpleNegation ) ;
661661 }
662+
663+ if ( kind == SyntaxKind . LogicalNotExpression &&
664+ _semanticModel . GetTypeInfo ( node . Operand ) . ConvertedType is { } t &&
665+ ( t . IsNumericType ( ) || t . IsEnumType ( ) ) ) {
666+ csTokenKind = SyntaxKind . TildeToken ;
667+ }
662668 return SyntaxFactory . PrefixUnaryExpression (
663669 kind ,
664670 SyntaxFactory . Token ( csTokenKind ) ,
Original file line number Diff line number Diff line change @@ -67,4 +67,13 @@ Public Class EnumTests
6767 Dim s As String = RankEnum.Second
6868 Assert.Equal(s & RankEnum.Second, "22" )
6969 End Sub
70+
71+ <Fact>
72+ Public Sub NegatedEnumNegatesUnderlyingNumber()
73+ Dim initialEnum = RankEnum.First Or RankEnum.Second
74+ Dim withSecondRemoved = initialEnum And Not RankEnum.Second
75+ Dim i As RankEnum = ( 1 Or 2 ) And Not 2
76+ Assert.Equal(withSecondRemoved, i)
77+ Assert.Equal(withSecondRemoved, RankEnum.First)
78+ End Sub
7079End Class
You can’t perform that action at this time.
0 commit comments