Skip to content

Account for partial properties at existing use sites of partial method symbol APIs #73772

@RikkiGibson

Description

@RikkiGibson

Test plan: #73090

Issue referenced in source

IDE

var symbol = model.GetSymbolInfo(invocation.Expression, cancellationToken).Symbol;
if (symbol is not IMethodSymbol method || method.PartialImplementationPart is not null)
{
// https://github.com/dotnet/roslyn/issues/73772: should we also bail out on a partial property?
// We don't handle partial methods yet
return null;
}

// https://github.com/dotnet/roslyn/issues/73772: should we also get partial property symbols here?
var symbols = semanticModel.LookupSymbols(position, container: enclosingSymbol)
.OfType<IMethodSymbol>()
.Where(m => IsPartial(m) && m.PartialImplementationPart == null);

// If this is a parameter symbol for a partial method definition, be sure we visited
// the implementation part's body.
// https://github.com/dotnet/roslyn/issues/73772: also do this for properties
if (renamedSymbol is IParameterSymbol renamedParameterSymbol &&
renamedSymbol.ContainingSymbol is IMethodSymbol methodSymbol &&
methodSymbol.PartialImplementationPart != null)
{

// https://github.com/dotnet/roslyn/issues/73772: add other partial property part as conflicting symbol
if (isMethod && conflictingSymbol is IMethodSymbol conflictingMethod && renamedMember is IMethodSymbol renamedMethod)
{
if (!(conflictingMethod.PartialDefinitionPart != null && Equals(conflictingMethod.PartialDefinitionPart, renamedMethod)) &&
!(conflictingMethod.PartialImplementationPart != null && Equals(conflictingMethod.PartialImplementationPart, renamedMethod)))
{
builder.AddRange(conflictingSymbol.Locations);
}
}

// https://github.com/dotnet/roslyn/issues/73772: define/use a similar helper for PropertySymbolReferenceFinder+PropertyAccessorSymbolReferenceFinder?
if (symbol.PartialDefinitionPart != null)
return [symbol.PartialDefinitionPart];
if (symbol.PartialImplementationPart != null)
return [symbol.PartialImplementationPart];

// https://github.com/dotnet/roslyn/issues/73772: also cascade partial indexer parameters
if (parameter.ContainingSymbol is IMethodSymbol method)
{
var ordinal = parameter.Ordinal;
if (ordinal < method.PartialDefinitionPart?.Parameters.Length)
results.Add(method.PartialDefinitionPart.Parameters[ordinal]);
if (ordinal < method.PartialImplementationPart?.Parameters.Length)
results.Add(method.PartialImplementationPart.Parameters[ordinal]);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions