Extensions: address some follow-ups related to using directives#79890
Extensions: address some follow-ups related to using directives#79890jcouv merged 2 commits intodotnet:mainfrom
using directives#79890Conversation
| internal void GetExtensionContainers(ArrayBuilder<NamedTypeSymbol> extensions) | ||
| { | ||
| // Consider whether IsClassType could be used instead. Tracked by https://github.com/dotnet/roslyn/issues/78275 | ||
| if (!IsReferenceType || !IsStatic || IsGenericType || !MightContainExtensionMethods) return; |
There was a problem hiding this comment.
Shouldn't we check !IsReferenceType || !IsStatic || IsGenericType inside MightContainExtensionMethods instead? #WontFix
There was a problem hiding this comment.
Yes, that would make sense.
As part of this PR, I'd identified a couple other questions/follow-ups regarding MightContainExtensionMethods. I captured them to this follow-up issue and captured your suggestion there as well.
I prefer to keep this PR very focused and keep this moved code as-is for now. I'll take a stab at this in next PR, as it's bothering me too.
There was a problem hiding this comment.
Looked around a bit and it's already clear the answer is not obvious, so would rather not open a possible can of worms. See PENamedTypeSymbol.MightContainExtensionMethods:
public override bool MightContainExtensionMethods
{
get
{
var uncommon = GetUncommonProperties();
if (uncommon == s_noUncommonProperties)
{
return false;
}
if (!uncommon.lazyContainsExtensionMethods.HasValue())
{
var contains = ThreeState.False;
// Dev11 supports extension methods defined on non-static
// classes, structs, delegates, and generic types.
switch (this.TypeKind)
{
case TypeKind.Class:
case TypeKind.Struct:
case TypeKind.Delegate:
...
Addresses parts of #78827
Note: an implementation method for a non-static new extension method is an extension method, and therefore not imported as a static method (existing behavior, see
IsValidLookupCandidateInUsings) and cannot be invoked directly. It can only be called by extension invocation.Relates to test plan #76130