-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added unary operator expression tests #18136
added unary operator expression tests #18136
Conversation
@dotnet/analyzer-ioperation @AlekseyTs can you take a look? |
|
||
"; | ||
string expectedOperationTree = @" | ||
IUnaryOperatorExpression (UnaryOperationKind.Invalid) (OperationKind.UnaryOperatorExpression, Type: System.Object, IsInvalid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure in C#, how I can get BooleanBitwiseNegation - http://source.roslyn.io/#Microsoft.CodeAnalysis/Compilation/IExpression.cs,529
which seems possible according to this
http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/BoundTree/Expression.cs,2452
string expectedOperationTree = @" | ||
IUnaryOperatorExpression (UnaryOperationKind.Invalid) (OperationKind.UnaryOperatorExpression, Type: System.Object, IsInvalid) | ||
IInvocationExpression ( System.Double A.Method()) (OperationKind.InvocationExpression, Type: System.Double) | ||
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how to get DynamicTrue and DynamicFalse
http://source.roslyn.io/#Microsoft.CodeAnalysis/Compilation/IExpression.cs,544
Dim expectedOperationTree = <![CDATA[ | ||
IUnaryOperatorExpression (UnaryOperationKind.OperatorMethodBitwiseNegation) (OperatorMethod: Function CustomType.op_OnesComplement(x As CustomType) As CustomType) (OperationKind.UnaryOperatorExpression, Type: CustomType) | ||
IInvocationExpression ( Function A.Method() As CustomType) (OperationKind.InvocationExpression, Type: CustomType) | ||
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how to get OperatorMethodTrue/False
even if I implement IsTrue/IsFalse/Or/And Operators, it doesn't get returned by GetOperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
behavior of IfStatement Operation between VB and C# seems different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if I implement IsTrue/IsFalse/Or/And Operators, it doesn't get returned by GetOperation
That is probably a bug. Can you add test case, and skip it with a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented true and false test
]]>.Value | ||
|
||
Dim expectedOperationTree = <![CDATA[ | ||
IUnaryOperatorExpression (UnaryOperationKind.BooleanBitwiseNegation) (OperationKind.UnaryOperatorExpression, Type: System.Boolean) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no LogicalNot in VB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some. From language spec, section 11.17 Logical Operators:
The And, Not, Or, and Xor operators, which are called the logical operators, are evaluated as follows: ...
However, we should figure out how do they map to IOperation universe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlekseyTs @cston @jcouv what would be example of VB code that will use LogicalNot in bound node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dim b As Boolean = False
Return Not b
It looks like Expression.DeriveUnaryOperationKind
maps System_Boolean
+ Not
to UnaryOperationKind.BooleanBitwiseNegation
rather than UnaryOperationKind.BooleanLogicalNot
though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like in VB, there is no way to distinguish between BooleanLogicalNot and BooleanBitwiseNegation and looks like later one is choosen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the difference that LogicalNot
is an operation on boolean and BitwiseNegation
is an operation on integer types? For instance, Not b
is a LogicalNot
and Not i
is BitwiseNegation
below (equivalent to !b
and ~i
in C#?).
Dim b = False
System.Console.WriteLine(Not b)
Dim i = 25
System.Console.WriteLine(Not i)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cston for those, there is IntergerBitwiseNegation kind. (http://source.roslyn.io/#Microsoft.CodeAnalysis/Operations/UnaryOperationKind.cs,25)
@mavasani can you take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good test coverage! I see there are 2 possible product bugs, please file them.
Someone from the compiler team can answer your language related questions.
|
||
|
||
[Fact] | ||
public void Test_UnaryOperatorExpression_Type_Minus_System_SByte() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests seem very comprehensive, and I see that you have covered all the possible combinations of the huge UnaryOperationKind enum 👍
System.Byte Method() | ||
{ | ||
System.Byte i = default(System.Byte); | ||
return /*<bind>*/+Method()/*</bind>*/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we are getting much value add in testing +i
in prior tests versus +Method()
in these tests. You can probably change i
to be a constant in previous tests to get different coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or I would just delete the +Method()
tests unless you feel they are covering a different code path for binding unary operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since Operand can be any expression, I wanted to have at least 2 different kind of expression there. if you have better expression to use there, let me know.
|
||
|
||
[Fact] | ||
public void Test_UnaryOperatorExpression_Method_BitwiseNot_System_SByte() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I don't see much value add in these ~Method()
tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests are generated ha ha, that is why some tests are invalid :)
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even valid code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no valid code, so result shows OperationKind.Invalid. do you only cover valid case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you should add even invalid code tests.
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also have 2 ILocalReferenceExpression for reference to locals x and y - seems like a bug that it is missing. Can you file a bug please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mavasani I couldn't find which test you are refering to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to https://github.com/dotnet/roslyn/pull/18136/files/74264afab568fc249c1f2ea0ad5552d8a2d24493#diff-b08381441daffef52069a7ea362ff9faR2660. IOperation for x && y
should have local references I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dim expectedOperationTree = <![CDATA[ | ||
IUnaryOperatorExpression (UnaryOperationKind.OperatorMethodBitwiseNegation) (OperatorMethod: Function CustomType.op_OnesComplement(x As CustomType) As CustomType) (OperationKind.UnaryOperatorExpression, Type: CustomType) | ||
IInvocationExpression ( Function A.Method() As CustomType) (OperationKind.InvocationExpression, Type: CustomType) | ||
Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if I implement IsTrue/IsFalse/Or/And Operators, it doesn't get returned by GetOperation
That is probably a bug. Can you add test case, and skip it with a bug?
@dotnet/roslyn-infrastructure is this known issue? error VSSDK1081: Problem occurred while extracting the vsix to the experimental extensions path. [D:\j\workspace\windows_relea---8a39a417\src\VisualStudio\Setup.Dependencies\VisualStudioSetup.Dependencies.csproj] https://ci.dot.net/job/dotnet_roslyn/job/master/job/windows_release_vs-integration_prtest/1668/ |
@AlekseyTs can you take a look? |
@dotnet/analyzer-ioperation can someone else take a look as well? |
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not all facts have workitem associated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is all same workitem so I skipped it except the first one :)
@AlekseyTs I have 2 sign off, can you take a look as final decider? |
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test_UnaryOperatorExpression_Method_LogicalNot_CustomType [](start = 20, length = 57)
It would be good to have tests for a scenario when CustomType doesn't have the right user-defined operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CustomType CustomType.op_UnaryPlus(CustomType x) [](start = 82, length = 48)
Is it possible to come up with a scenario when UnaryOperationKind is UnaryOperationKind.OperatorMethodPlus, but the corresponding OperatorMethod is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like without operatormethod, kind becomes invalid
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test_UnaryOperatorExpression_Type_Plus_CustomType [](start = 20, length = 49)
Consider testing scenarios when input, or output types for user-defined operators do not match CustomType exactly, including scenarios when input conversion exists and doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VerifyOperationTreeForTest(source, expectedOperationTree); [](start = 12, length = 77)
Consider also checking the tree for x && y
expression rather than for the entire if
. Also, could be useful to test expressions outside of if
context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracked by #18160
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test_UnaryOperatorExpression_Type_Or_TrueFalse [](start = 20, length = 46)
Consider testing scenarios:
- involving conversions;
- with missing or malformed operators (some, all, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
} | ||
|
||
"; | ||
string expectedOperationTree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider testing:
- increment/decrement operators;
- nullable operators.
- pointer operators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont believe those are considered unary operator, but sure. I can add tests for those
]]>.Value | ||
|
||
Dim expectedOperationTree = <
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
VerifyOperationTreeForTest(Of MultiLineIfBlockSyntax)(source, expectedOperationTree) | ||
End Sub | ||
End Class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End Class [](start = 4, length = 9)
Many test suggestions for C# are applicable to VB as well.
Done with review pass. |
3f1c235
to
962dd86
Compare
added vb unary operator tests
962dd86
to
602274b
Compare
@dotnet/roslyn-compiler @dotnet/analyzer-ioperation adding unary operator unit tests. can you take a look? |
ping? |
There should probably be a Trait or CompilerFeature to tag all the IOperations tests. Refers to: src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IUnaryOperatorExpression.cs:9 in dd17e7b. [](commit_id = dd17e7b, deletion_comment = False) |
tag #20652 |
@roslyn-compiler Is this conversion expected? I didn't understand why it is there. Refers to: src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IUnaryOperatorExpression.cs:386 in dd17e7b. [](commit_id = dd17e7b, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@dotnet/roslyn-infrastructure windows_debug_vs-integration_prtest failed with no failed test |
retest windows_debug_vs-integration_prtest please |
integration test failure is known issue |
this includes only csharp tests. I will add vb tests next.