Skip to content

Fix 'quick info' and 'use explicit type' for implicit lambdas#55290

Merged
CyrusNajmabadi merged 6 commits intodotnet:mainfrom
CyrusNajmabadi:lambdaFixes
Aug 3, 2021
Merged

Fix 'quick info' and 'use explicit type' for implicit lambdas#55290
CyrusNajmabadi merged 6 commits intodotnet:mainfrom
CyrusNajmabadi:lambdaFixes

Conversation

@CyrusNajmabadi
Copy link
Copy Markdown
Contributor

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from cston July 30, 2021 18:48
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners July 30, 2021 18:48
@ghost ghost added the Area-IDE label Jul 30, 2021

public static bool IsAnonymousDelegateType([NotNullWhen(returnValue: true)] this ISymbol? symbol)
=> symbol.IsAnonymousType() && symbol.IsDelegateType();
=> symbol.IsDelegateType() && (symbol.IsAnonymousType() || !symbol.CanBeReferencedByName);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

vb and C# are a bit weird here. VB represents anonymous lambdas as actual .IsAnonymousType. C# does not, but instead has CanBeReferencedByName=false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was there an explicit decision here by the compiler team to use CanBeReferencedByName over IsAnonymousType as the api shape? Wish these could be consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cston any thoughts on why VB/C# differ here wrt anonymous delegates?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It feels like SynthesizedDelegateSymbol.IsAnonymousType should return true. Please feel free to change that or log an issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd agree with Chuck.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs Outdated
Copy link
Copy Markdown
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

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

🕐

Copy link
Copy Markdown
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment thread src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs Outdated
@CyrusNajmabadi CyrusNajmabadi changed the base branch from main to release/dev17.0 July 30, 2021 19:30
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

@jinujoseph Need approval on this. This is for some high profile ugliness cases we get with the new anonymous-lambda work that compiler just merged in.

@cston
Copy link
Copy Markdown
Contributor

cston commented Jul 30, 2021

@dotnet/roslyn-compiler for a second review, thanks.

@CyrusNajmabadi CyrusNajmabadi changed the base branch from release/dev17.0 to main July 30, 2021 20:01
@CyrusNajmabadi
Copy link
Copy Markdown
Contributor Author

Moving over to main.

@CyrusNajmabadi CyrusNajmabadi changed the base branch from main to release/dev17.0 July 30, 2021 20:11
Comment thread src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs Outdated
Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM, assuming my question around localization is answered with "no, we don't do that for this type."


public static bool IsAnonymousDelegateType([NotNullWhen(returnValue: true)] this ISymbol? symbol)
=> symbol.IsAnonymousType() && symbol.IsDelegateType();
=> symbol.IsDelegateType() && (symbol.IsAnonymousType() || !symbol.CanBeReferencedByName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd agree with Chuck.

$$var v = (int i) => i.ToString();
}
}",
MainDescription("delegate TResult System.Func<in T, out TResult>(T arg)"),
Copy link
Copy Markdown
Member

@jcouv jcouv Jul 31, 2021

Choose a reason for hiding this comment

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

Shouldn't this just be System.Func<...>? I don't understand the combination of System.Func... with delegate and a method signature. #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So Func is a delegate, so we show that (just like we say if something is a class/struct). And for delegates we show the signature as that's what's relevant a lot of the time. So this is standard for how we've shown this information for about 15 years :-)

{
void M()
{
var v = (ref int i) => i.ToString();
Copy link
Copy Markdown
Member

@jcouv jcouv Jul 31, 2021

Choose a reason for hiding this comment

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

Could you include a similar test for a "simple signature" (no ref)? #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure!

@jcouv jcouv self-assigned this Jul 31, 2021
@@ -319,17 +319,13 @@ public static bool ContainsAnonymousType([NotNullWhen(returnValue: true)] this I

private static bool ContainsAnonymousType(INamedTypeSymbol type)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we remove this method and overload on line 309?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Kindly ping on this question

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i don't really know what you mean. How would we remove it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm suggesting we delete lines 309 through 332.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why would we do that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Arg. My bad. When I'd done a FindAllRefs, I'd only found those two methods referencing each other... But in actuality they are used...
Good to go then. Thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

basically, i don't understand the motivation here. why would we remove these helpers? and what is your suggestion on what to do about the breakage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it :) ok.

Copy link
Copy Markdown
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.

Done with review pass (iteration 6)

Copy link
Copy Markdown
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 Thanks (iteration 6) modulo question left about removing method rather than updating it.

@CyrusNajmabadi CyrusNajmabadi changed the base branch from release/dev17.0 to main August 3, 2021 18:55
@CyrusNajmabadi CyrusNajmabadi merged commit 416765f into dotnet:main Aug 3, 2021
@ghost ghost added this to the Next milestone Aug 3, 2021
@CyrusNajmabadi CyrusNajmabadi deleted the lambdaFixes branch August 3, 2021 18:56
@dibarbet dibarbet modified the milestones: Next, 17.0.P4 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants