Skip to content
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

Merged
merged 5 commits into from
Jul 5, 2017

Conversation

heejaechang
Copy link
Contributor

this includes only csharp tests. I will add vb tests next.

@heejaechang
Copy link
Contributor Author

@dotnet/analyzer-ioperation @AlekseyTs can you take a look?


";
string expectedOperationTree = @"
IUnaryOperatorExpression (UnaryOperationKind.Invalid) (OperationKind.UnaryOperatorExpression, Type: System.Object, IsInvalid)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no LogicalNot in VB?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heejaechang
Copy link
Contributor Author

@mavasani can you take a look?

Copy link
Contributor

@mavasani mavasani left a 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()
Copy link
Contributor

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>*/;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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

Copy link
Contributor Author

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 =
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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 =
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

@heejaechang
Copy link
Contributor Author

@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/

@heejaechang
Copy link
Contributor Author

@AlekseyTs can you take a look?

@heejaechang
Copy link
Contributor Author

@dotnet/analyzer-ioperation can someone else take a look as well?

}

";
string expectedOperationTree =
Copy link
Contributor

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

Copy link
Contributor Author

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 :)

@heejaechang
Copy link
Contributor Author

@AlekseyTs I have 2 sign off, can you take a look as final decider?

}

";
string expectedOperationTree =
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}

";
string expectedOperationTree =
Copy link
Contributor

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?

Copy link
Contributor Author

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 =
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}

";
string expectedOperationTree =
Copy link
Contributor

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.

Copy link
Contributor Author

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 =
Copy link
Contributor

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.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}

";
string expectedOperationTree =
Copy link
Contributor

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.

Copy link
Contributor Author

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 = <![CDATA[
IConversionExpression (ConversionKind.Basic, Implicit) (OperationKind.ConversionExpression, Type: E)
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this conversion in the tree? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a design issue, it looks like language doesn't say explicitly that +/- are supported for enums (sections 11.13.1 Unary Plus Operator and 11.13.2 Unary Minus Operator).


In reply to: 108308547 [](ancestors = 108308547)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct after all.


In reply to: 108309336 [](ancestors = 108309336,108308547)


VerifyOperationTreeForTest(Of MultiLineIfBlockSyntax)(source, expectedOperationTree)
End Sub
End Class
Copy link
Contributor

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.

@AlekseyTs
Copy link
Contributor

Done with review pass.

@heejaechang heejaechang changed the base branch from master to features/ioperation June 30, 2017 21:50
@heejaechang heejaechang changed the base branch from features/ioperation to master June 30, 2017 21:50
added vb unary operator tests
@heejaechang heejaechang changed the base branch from master to features/ioperation June 30, 2017 23:11
@heejaechang
Copy link
Contributor Author

@dotnet/roslyn-compiler @dotnet/analyzer-ioperation adding unary operator unit tests. can you take a look?

@heejaechang
Copy link
Contributor Author

ping?

@jcouv
Copy link
Member

jcouv commented Jul 5, 2017

public partial class IOperationTests : SemanticModelTestBase

There should probably be a Trait or CompilerFeature to tag all the IOperations tests.
[This can wait til another PR]


Refers to: src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IUnaryOperatorExpression.cs:9 in dd17e7b. [](commit_id = dd17e7b, deletion_comment = False)

@jcouv
Copy link
Member

jcouv commented Jul 5, 2017

    [Fact]

Nit: double empty lines (here and below).


Refers to: src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IUnaryOperatorExpression.cs:34 in dd17e7b. [](commit_id = dd17e7b, deletion_comment = False)

@heejaechang
Copy link
Contributor Author

tag #20652

@jcouv
Copy link
Member

jcouv commented Jul 5, 2017

IConversionExpression (ConversionKind.CSharp, Implicit) (OperationKind.ConversionExpression, Type: System.Int32) (Syntax: 'i')

@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)

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@heejaechang
Copy link
Contributor Author

@dotnet/roslyn-infrastructure windows_debug_vs-integration_prtest failed with no failed test

https://ci.dot.net/job/dotnet_roslyn/job/features_ioperation/job/windows_debug_vs-integration_prtest/154/

@heejaechang
Copy link
Contributor Author

retest windows_debug_vs-integration_prtest please

@cston
Copy link
Member

cston commented Jul 5, 2017

The two recent failures of windows_debug_vs-integration_prtest are known issues: #20567 and #20562.

@heejaechang heejaechang merged commit 49a5693 into dotnet:features/ioperation Jul 5, 2017
@heejaechang
Copy link
Contributor Author

integration test failure is known issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants