Extensions: Add ReduceExtensionMember API#80659
Conversation
bd1e5af to
cadd91d
Compare
cadd91d to
a151018
Compare
| IMethodSymbol? ReduceExtensionMethod(ITypeSymbol receiverType); | ||
|
|
||
| /// <summary> | ||
| /// If this is a (new) extension method that can be applied to a receiver of the given type, |
| if (_underlying.GetIsNewExtensionMember() && SourceMemberContainerTypeSymbol.IsAllowedExtensionMember(_underlying)) | ||
| { | ||
| var csharpReceiver = receiverType.EnsureCSharpSymbolOrNull(nameof(receiverType)); | ||
| return (IMethodSymbol?)SourceNamedTypeSymbol.GetCompatibleSubstitutedMember(compilation: null, _underlying, csharpReceiver, wasExtensionFullyInferred: out _).GetPublicSymbol(); |
There was a problem hiding this comment.
I don't think so. See description in OP: "For lookup, we do want to return members that can't be fully inferred."
| if (_underlying.GetIsNewExtensionMember() && SourceMemberContainerTypeSymbol.IsAllowedExtensionMember(_underlying)) | ||
| { | ||
| var csharpReceiver = receiverType.EnsureCSharpSymbolOrNull(nameof(receiverType)); | ||
| return (IPropertySymbol?)SourceNamedTypeSymbol.GetCompatibleSubstitutedMember(compilation: null, _underlying, csharpReceiver, wasExtensionFullyInferred: out _).GetPublicSymbol(); |
|
|
||
| INamedTypeSymbol systemObject = comp.GetSpecialType(SpecialType.System_Object).GetPublicSymbol(); | ||
|
|
||
| AssertEx.Equal("void E.<G>$66F77D1E46F965A5B22D4932892FA78B<T>.M()", method.ToTestDisplayString()); |
| } | ||
|
|
||
| [Fact] | ||
| public void ReduceExtensionMember_12() |
There was a problem hiding this comment.
That's correct, this is testing the internal API which has a different name, but is morally equivalent. I don't think this warrants a different test name. An alternative would be to rename the internal API to use the same name as the public one.
| } | ||
|
|
||
| [Fact] | ||
| public void ReduceExtensionMember_13() |
|
Done with review pass (Commit 1) #Closed |
|
@RikkiGibson @CyrusNajmabadi for second review. Thanks |
1 similar comment
|
@RikkiGibson @CyrusNajmabadi for second review. Thanks |
| /// <summary> | ||
| /// If this is a method of an extension block that can be applied to a receiver of the given type, | ||
| /// returns the method symbol in the substituted extension for that receiver type. Otherwise, returns null. | ||
| /// </summary> |
There was a problem hiding this comment.
i think it would be really good to give an explicit code example of what this is versus ReduceExtensionMethod
There was a problem hiding this comment.
I'll do a follow-up PR for this
Closes #80273 (pending API review to decide whether to have an API on ISymbol or split as implemented here)
There is a small change in behavior when dealing with extensions that aren't fully inferred. Previously,
GetCompatibleSubstitutedMemberdropped them. Now, it's up to the caller to decide.The
LookupSymbols_WasNotFullyInferredtest illustrates such a change. For lookup, we do want to return members that can't be fully inferred.Relates to test plan #76130