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

ported tests from https://github.com/dotnet/roslyn/pull/21263 #22296

Merged
merged 3 commits into from
Sep 23, 2017

Conversation

heejaechang
Copy link
Contributor

main issue the PR is trying to fix (#18405) is addressed by this (#21857).

this mainly port over tests added by this pr (#21263) with some changes.

in some cases such as params array, argument node get removed while converted to IOperation since compiler generated array replaces the argument.

for those, I just made test to dump including statement. for now, the test doesn't show interesting info, but once @jinujoseph finishes the work to show syntax kind/isImplicit/parent in the test, it will show info such as what got injected (param array) and argument got removed.

@heejaechang
Copy link
Contributor Author

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

}
";
string expectedOperationTree = @"
IArgument (ArgumentKind.Explicit, Matching Parameter: i) (OperationKind.Argument) (Syntax: 'ref i')
Copy link
Contributor

@mavasani mavasani Sep 22, 2017

Choose a reason for hiding this comment

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

Just realized that we don't expose the RefKind of the argument on IArgument node. Should we do so? Can you please file a tracking bug? #Resolved

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

sure - #22297 #Resolved

Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'this')
Arguments(1):
IArgument (ArgumentKind.ParamArray, Matching Parameter: array) (OperationKind.Argument) (Syntax: 'this[1]')
IArrayCreationExpression (Element Type: System.Int32) (OperationKind.ArrayCreationExpression, Type: System.Int32[]) (Syntax: 'this[1]')
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the synthesized one correct? It still looks like a bug that the associated syntax is this[1] and not 1. Can you file an issue to track this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1 seems as weird as this[1] for me :) not sure what is right node to put here though :)

opened -#22298

IObjectCreationExpression (Constructor: Sub Program..ctor(ParamArray a As System.Int32())) (OperationKind.ObjectCreationExpression, Type: Program) (Syntax: 'New Program(1)')
Arguments(1):
IArgument (ArgumentKind.ParamArray, Matching Parameter: a) (OperationKind.Argument) (Syntax: 'Program')
IArrayCreationExpression (Element Type: System.Int32) (OperationKind.ArrayCreationExpression, Type: System.Int32()) (Syntax: 'Program')
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, associated syntax seems weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. the pattern looks like assigning node above itself regardless what that is.

@jinujoseph
Copy link
Contributor

@dotnet/roslyn-compiler

@heejaechang
Copy link
Contributor Author

jenkins issue - CSC : error CS0016: Could not write to output file 'D:\j\workspace\windows_deter---bd1d49d3\Binaries\Obj\TestUtilities\Debug\Roslyn.Test.Utilities.xml' -- 'The process cannot access the file 'D:\j\workspace\windows_deter---bd1d49d3\Binaries\Obj\TestUtilities\Debug\Roslyn.Test.Utilities.xml' because it is being used by another process.' [D:\j\workspace\windows_deter---bd1d49d3\src\Test\Utilities\Portable\TestUtilities.csproj]

@heejaechang
Copy link
Contributor Author

retest windows_determinism_prtest please

int i = 0;
M2(/*<bind>*/ref i/*</bind>*/);
}
static void M2(ref int i) { }
Copy link
Member

@jcouv jcouv Sep 22, 2017

Choose a reason for hiding this comment

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

Consider adding a similar test for "ref readonly" parameter.

int i = 0;
ref int refI = ref i;
M2(refI);

FYI @VSadov #Resolved

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

sure. #Resolved

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

@jcouv what feature option do I need to turn on to make ref readonly to work? #Resolved

Copy link
Member

Choose a reason for hiding this comment

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

LangVersion.CSharp7_2 on latest master bits.


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

Copy link
Member

@jcouv jcouv Sep 22, 2017

Choose a reason for hiding this comment

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

Sorry, had made a mistake above. No "ref readonly" at callsite. #Resolved

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 added test but not sure what kind of info we are looking for from IArgument. the difference seems all in IParameter not on callsite.

Copy link
Member

Choose a reason for hiding this comment

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

We may need to a follow-up on that.


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

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 @jinujoseph are we going to support the "ref readonly" feature in IOperation v1?

}
";
string expectedOperationTree = @"
IArgument (ArgumentKind.Explicit, Matching Parameter: i) (OperationKind.Argument) (Syntax: 'ref i')
Copy link
Member

@jcouv jcouv Sep 22, 2017

Choose a reason for hiding this comment

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

That's pretty useful. I was just wondering about this a couple of days ago, do we have public API to show how arguments and parameters were matched... #Resolved

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

tagging @genlu who did argument work. #Resolved

{
static void M1()
{
/*<bind>*/M2(0, 1);/*</bind>*/
Copy link
Member

@jcouv jcouv Sep 22, 2017

Choose a reason for hiding this comment

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

Maybe that is tested elsewhere: what happens if the "bind" tags are just around "0" or "1" in this scenario? #Resolved

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

depends on whether it is literal expression or argument syntax node given. if it is literal expression, then it will return ILiteralExpression. if it is argument syntax, then it will return nothing since that node doesn't exist in IOperation tree. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is what I meant in the description.

"for now, the test doesn't show interesting info, but once @jinujoseph finishes the work to show syntax kind/isImplicit/parent in the test, it will show info such as what got injected (param array) and argument got removed."

VerifyOperationTreeAndDiagnosticsForTest<ElementAccessExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}

[Fact]
Copy link
Member

Choose a reason for hiding this comment

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

I don't know how attributes work with IOperation, but something like [MyAttribute(0, 1)] would be useful to test.
Attributes (in C#) can also initialize properties: [MyAttribute(arg1: 1, arg2: 2, Property1=1, Property2=2)].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added. looks like we don't support bound attribute fully yet.

var expectedDiagnostics = DiagnosticDescription.None;

VerifyOperationTreeAndDiagnosticsForTest<ElementAccessExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
Copy link
Member

Choose a reason for hiding this comment

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

Another scenario that may be worth testing is non-trailing named arguments: M(a: 1, 2) (C# 7.2). This should behave the same as if the argument name wasn't there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -1074,5 +1074,269 @@ End Class]]>.Value

VerifyClone(model)
End Sub

<Fact>
Copy link
Member

Choose a reason for hiding this comment

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

If I remember correctly, VB not only has named, un-named and omitted arguments, it also has "range" arguments. I'm not sure the syntax.

Copy link
Contributor Author

@heejaechang heejaechang Sep 22, 2017

Choose a reason for hiding this comment

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

added. but the range argument is added implicit operation so it won't return by GetOperation(range argument)

public void DirectlyBindArgument_Attribute()
{
string source = @"
[assembly: /*<bind>*/System.CLSCompliant(isCompliant: true)/*</bind>*/]
Copy link
Member

Choose a reason for hiding this comment

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

Is there a tracking issue for attributes?

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 this - #18198

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

do I need one more sign off for test only change from compiler team?

@jinujoseph
Copy link
Contributor

No, test only changes 1 sign off needed.

@heejaechang
Copy link
Contributor Author

@dotnet/roslyn-infrastructure test failed - Roslyn.VisualStudio.IntegrationTests.VisualBasic.BasicLineCommit.CommitOnSave

https://ci.dot.net/job/dotnet_roslyn/job/master/job/windows_release_vs-integration_prtest/7913/

@heejaechang
Copy link
Contributor Author

retest windows_release_vs-integration_prtest please

@heejaechang heejaechang merged commit 917edc1 into dotnet:master Sep 23, 2017
333fred added a commit to 333fred/roslyn that referenced this pull request Sep 25, 2017
* dotnet/master: (351 commits)
  Avoid scheduling an unnecessary dispose task for EmptyAsyncToken
  Support for ref-readonly locals (dotnet#22269)
  ported tests from dotnet#21263 (dotnet#22296)
  NormalizeWhitespace should not add a space in nullable type (dotnet#22234)
  Fix the work item number associated with the unit test
  Add unit test
  Terminate a sentence
  Add instructions for upgrading PowerShell
  Unsafe local should require /unsafe flag on compilation (dotnet#22268)
  CR feedback
  Not poisoning restricted types known to be stack only.
  Typo
  Error messsage should mention C# 7.0 not C# 7 (dotnet#22255)
  Package descriptions for CSharp and VB should include summary blurb (dotnet#22166)
  Fix a trivial issue in how IsLifted is calculated for C# compound assignment operator
  Do not zero out "With" statement target expression locals referenced within a lambda. (dotnet#22223)
  Fix unit test failure from merge
  Mark "private protected", "ref readonly" and other C# 7.2 features as merged (dotnet#22209)
  Add unit tests for IAwaitExpression and make the API public again
  more test fixes due to merge conflicts
  ...
333fred added a commit to 333fred/roslyn that referenced this pull request Sep 28, 2017
* dotnet/master: (309 commits)
  Avoid scheduling an unnecessary dispose task for EmptyAsyncToken
  Support for ref-readonly locals (dotnet#22269)
  ported tests from dotnet#21263 (dotnet#22296)
  NormalizeWhitespace should not add a space in nullable type (dotnet#22234)
  Fix the work item number associated with the unit test
  Add unit test
  Terminate a sentence
  Add instructions for upgrading PowerShell
  Unsafe local should require /unsafe flag on compilation (dotnet#22268)
  CR feedback
  Not poisoning restricted types known to be stack only.
  Typo
  Error messsage should mention C# 7.0 not C# 7 (dotnet#22255)
  Package descriptions for CSharp and VB should include summary blurb (dotnet#22166)
  Fix a trivial issue in how IsLifted is calculated for C# compound assignment operator
  Do not zero out "With" statement target expression locals referenced within a lambda. (dotnet#22223)
  Fix unit test failure from merge
  Mark "private protected", "ref readonly" and other C# 7.2 features as merged (dotnet#22209)
  Add unit tests for IAwaitExpression and make the API public again
  more test fixes due to merge conflicts
  ...
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.

None yet

5 participants