Skip to content

Commit 7495823

Browse files
Fixup top level local functinos
1 parent 22dcea4 commit 7495823

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

src/EditorFeatures/Test2/FindReferences/FindReferencesTests.vb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
1111
Imports Microsoft.CodeAnalysis.FindSymbols
1212
Imports Microsoft.CodeAnalysis.FindUsages
1313
Imports Microsoft.CodeAnalysis.Host
14-
Imports Microsoft.CodeAnalysis.Options
1514
Imports Microsoft.CodeAnalysis.PooledObjects
1615
Imports Microsoft.CodeAnalysis.Remote.Testing
1716
Imports Microsoft.CodeAnalysis.Test.Utilities.FindUsages
1817
Imports Microsoft.CodeAnalysis.Text
19-
Imports Microsoft.CodeAnalysis.VisualBasic.Completion.KeywordRecommenders.PreprocessorDirectives
2018
Imports Roslyn.Utilities
2119
Imports Xunit.Abstractions
2220

src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractTypeParameterSymbolReferenceFinder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ void GetObjectCreationReferences(
5959
{
6060
foreach (var token in objectCreationTokens)
6161
{
62-
Contract.ThrowIfNull(token.Parent?.Parent);
63-
var typeInfo = state.SemanticModel.GetTypeInfo(token.Parent.Parent, cancellationToken);
64-
if (SymbolEquivalenceComparer.Instance.Equals(symbol, typeInfo.Type))
62+
Contract.ThrowIfNull(token.Parent);
63+
//var typeInfo = state.SemanticModel.GetTypeInfo(token.Parent.Parent, cancellationToken);
64+
//if (SymbolEquivalenceComparer.Instance.Equals(symbol, typeInfo.Type))
65+
// processResult(CreateFinderLocation(state, token, CandidateReason.None, cancellationToken), processResultData);
66+
var boundSymbol = state.SemanticModel.GetSymbolInfo(token.Parent, cancellationToken).Symbol;
67+
if (SymbolEquivalenceComparer.Instance.Equals(symbol, boundSymbol))
6568
processResult(CreateFinderLocation(state, token, CandidateReason.None, cancellationToken), processResultData);
6669
}
6770
}

src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/MethodTypeParameterSymbolReferenceFinder.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,34 @@ protected sealed override Task DetermineDocumentsToSearchAsync<TData>(
4747
FindReferencesSearchOptions options,
4848
CancellationToken cancellationToken)
4949
{
50-
// Type parameters are only found in documents that have both their name, and the name
51-
// of its owning method. NOTE(cyrusn): We have to check in multiple files because of
52-
// partial types. A type parameter can be referenced across all the parts. NOTE(cyrusn):
53-
// We look for type parameters by name. This means if the same type parameter has a
54-
// different name in different parts that we won't find it. However, this only happens
55-
// in error situations. It is not legal in C# to use a different name for a type
56-
// parameter in different parts.
50+
// Type parameters are only found in documents that have both their name, and the name of its owning method.
51+
// NOTE(cyrusn): We have to check in multiple files because of partial types. A type parameter can be
52+
// referenced across all the parts. NOTE(cyrusn): We look for type parameters by name. This means if the same
53+
// type parameter has a different name in different parts that we won't find it. However, this only happens in
54+
// error situations. It is not legal in C# to use a different name for a type parameter in different parts.
5755
//
58-
// Also, we only look for files that have the name of the owning type. This helps filter
59-
// down the set considerably.
56+
// Also, we only look for files that have the name of the owning type. This helps filter down the set
57+
// considerably. Note: we don't do this for top level local functions as they obviously appear only in one
58+
// document, and their containing type name ("Program") doesn't have to appear there at all.
59+
6060
Contract.ThrowIfNull(symbol.DeclaringMethod);
61-
return FindDocumentsAsync(project, documents, processResult, processResultData, cancellationToken, symbol.Name,
62-
GetMemberNameWithoutInterfaceName(symbol.DeclaringMethod.Name),
63-
symbol.DeclaringMethod.ContainingType.Name);
61+
if (symbol is
62+
{
63+
ContainingSymbol: IMethodSymbol { MethodKind: MethodKind.LocalFunction },
64+
ContainingType: INamedTypeSymbol { Name: "Program", ContainingNamespace.IsGlobalNamespace: true }
65+
})
66+
{
67+
return FindDocumentsAsync(project, documents, processResult, processResultData, cancellationToken,
68+
symbol.Name,
69+
GetMemberNameWithoutInterfaceName(symbol.DeclaringMethod.Name));
70+
}
71+
else
72+
{
73+
return FindDocumentsAsync(project, documents, processResult, processResultData, cancellationToken,
74+
symbol.Name,
75+
GetMemberNameWithoutInterfaceName(symbol.DeclaringMethod.Name),
76+
symbol.DeclaringMethod.ContainingType.Name);
77+
}
6478
}
6579

6680
private static string GetMemberNameWithoutInterfaceName(string fullName)

0 commit comments

Comments
 (0)