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

Fixes #18311 - Incorrect quick info for ValueTuple<T> #18489

Merged
merged 2 commits into from
Apr 7, 2017
Merged

Fixes #18311 - Incorrect quick info for ValueTuple<T> #18489

merged 2 commits into from
Apr 7, 2017

Conversation

d0pare
Copy link

@d0pare d0pare commented Apr 6, 2017

Fixes #18311
Closes #15508

Hovering var will show System.ValueTuple<System.Int32>
Hovering y will show (local variable) ValueTuple<int> y

@CyrusNajmabadi
Copy link
Member

Need tests :)

They can be added to: https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/CSharpTest/QuickInfo/SemanticQuickInfoSourceTests.cs

Also, tagging @dotnet/roslyn-compiler as this changes compiler code.

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Fixing tests

@CyrusNajmabadi
Copy link
Member

Also, does the same issue for VB? If so, we should fix that as well.

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

VB is ok. Working on new tests.

@jcouv
Copy link
Member

jcouv commented Apr 6, 2017

If there is any chance this same method is invoked again on the "rest" of the tuple (which nests the elements after the 7th), I'd recommend testing the case of an 8-tuple: (1, 2, ..., 8) or ValueTuple.Create(1, 2, ..., 7, ValueTuple.Create(8)).

@jcouv
Copy link
Member

jcouv commented Apr 6, 2017

Nice. LGTM and thanks!

@@ -381,6 +381,11 @@ private bool CanUseTupleTypeName(INamedTypeSymbol tupleSymbol)
{
INamedTypeSymbol currentUnderlying = tupleSymbol.TupleUnderlyingType;

if (currentUnderlying.Arity == 1)
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be <= 1? Is there a similar issue with zero arity value tuples?

Copy link
Author

@d0pare d0pare Apr 6, 2017

Choose a reason for hiding this comment

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

For < 1 case CanUseTupleTypeName method is not called. For zero arity everything works fine.

@CyrusNajmabadi
Copy link
Member

Still need quick info tests. Thanks! :)

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Need help. Cannot make unit test to work properly.
var y$$ = ValueTuple.Create(1); generates (local variable) ? y as actual description

@CyrusNajmabadi
Copy link
Member

Do you have the right usings in place in the test?

@CyrusNajmabadi
Copy link
Member

Note: look at TestResources.NetFX.ValueTuple.tuplelib_cs as well. It appears as if some tests manually concat that in to get the definition of ValueTuple, since it's not part of mscorlib.

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

I am using

await TestInMethodAsync(
@"
var y$$ = ValueTuple.Create(1);
",
                MainDescription("(local variable) ValueTuple<int> y"));

TestInMethodAsync imports System

@jcouv
Copy link
Member

jcouv commented Apr 6, 2017

You'll need to manually include the source for ValueTuple into the test. The mscorlib used in tests doesn't have ValueTuple yet.
Cyrus pointed out the resource string that will help.
Or you can just inline a small implementation (example).

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Thanks could fix the issue. Working on new tests.

@CyrusNajmabadi
Copy link
Member

Your "Adding new tests" commit doesn't seem to be adding any new tests :)

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Sorry, committed wrong file. Fixed.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

IDE side lgtm. Still needs compiler review.

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

@jcouv
Copy link
Member

jcouv commented Apr 6, 2017

@dotnet/roslyn-compiler for a second review of the compiler change.

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Squashed commits for next review

IL_0006: ldloc.0
IL_0007: ldfld ""(int) System.ValueTuple<int, int, int, int, int, int, int, (int)>.Rest""
IL_0007: ldfld ""ValueTuple<int> System.ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>.Rest""
Copy link
Member

Choose a reason for hiding this comment

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

The corresponding VB test should have required the same change.

Copy link
Member

Choose a reason for hiding this comment

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

➡️ As an update, this is now corrected.

@cston
Copy link
Member

cston commented Apr 6, 2017

Consider adding a simple SymbolDisplay test for both C# and for VB. See SymbolDisplayTests.Tuple.

@d0pare
Copy link
Author

d0pare commented Apr 6, 2017

Updated VB logic and tests. Working on new symbol display tests.

@sharwell sharwell added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 6, 2017
@sharwell
Copy link
Member

sharwell commented Apr 6, 2017

Hovering var will show System.ValueTuple<System.Int32>

I believe the conclusion in #18298 was we want to display System.ValueTuple<int> instead of System.ValueTuple<System.Int32> for this case. However, it's possible that the work to implement this behavior will be part of the other pull request.

@sharwell
Copy link
Member

sharwell commented Apr 6, 2017

@dopare It's possible that this pull request fixed the following issue which I found during an investigation of #15508. If that is the case, then this pull request likely fixes the last remaining issue with that issue.

void Foo()
{
    ValueTuple<int> y = ValueTuple.Create(1);
    y.Item1.ToString(); // Extract method for this line crashes the refactoring provider
}

@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

Added simple symbol display tests for C# and VB.
@sharwell Will check it.

@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

@sharwell I have manually tested this in latest Visual Studio 2017 with and without my changes.

Without my changes ExtractMethodCodeRefactoringProvider keeps crashing.

With my changes I could extract following method:

void Foo()
{
      ValueTuple<int> y = ValueTuple.Create(1);
      NewMethod(y);
}

private static void NewMethod(ValueTuple<int> y)
{
      y.Item1.ToString(); // Extract method for this line crashes the refactoring provider
}

@cston
Copy link
Member

cston commented Apr 7, 2017

LGTM thanks.

@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

Squashed all commits

@sharwell
Copy link
Member

sharwell commented Apr 7, 2017

@dopare The Extract Method tests are in ExtractMethodTests.cs and ExtractMethodTests.vb. I'm planning to add tests for the case I mentioned after this PR is merged, but if you want to tackle them now that you already fixed the issue feel free to. 😄

@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

@sharwell Will add those tests.

@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

@sharwell Added new extract method tests for C# and VB.

@sharwell
Copy link
Member

sharwell commented Apr 7, 2017

Look at @dopare, doing my work for me. 😎

@sharwell sharwell merged commit b6f7c5c into dotnet:master Apr 7, 2017
@d0pare
Copy link
Author

d0pare commented Apr 7, 2017

Wow thanks 👍

@d0pare d0pare deleted the bugfix/18311 branch April 7, 2017 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants