Skip to content

Commit

Permalink
Symbol equivalence should consider tuple names
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Feb 24, 2018
1 parent 3c770bc commit a75b2be
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5299,6 +5299,8 @@ public string ToMinimalDisplayString(SemanticModel semanticModel, int position,

public bool IsComImport => throw new NotImplementedException();

public ImmutableArray<string> TupleElementNames => throw new NotImplementedException();

#endregion
}

Expand Down
1 change: 1 addition & 0 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Microsoft.CodeAnalysis.Diagnostics.Telemetry.AnalyzerTelemetryInfo.OperationBloc
Microsoft.CodeAnalysis.ILocalSymbol.RefKind.get -> Microsoft.CodeAnalysis.RefKind
Microsoft.CodeAnalysis.IMethodSymbol.RefKind.get -> Microsoft.CodeAnalysis.RefKind
Microsoft.CodeAnalysis.IMethodSymbol.ReturnsByRefReadonly.get -> bool
Microsoft.CodeAnalysis.INamedTypeSymbol.TupleElementNames.get -> System.Collections.Immutable.ImmutableArray<string>
Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.IOperation.Accept(Microsoft.CodeAnalysis.Operations.OperationVisitor visitor) -> void
Microsoft.CodeAnalysis.IOperation.Accept<TArgument, TResult>(Microsoft.CodeAnalysis.Operations.OperationVisitor<TArgument, TResult> visitor, TArgument argument) -> TResult
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/Core/Portable/Symbols/INamedTypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@ public interface INamedTypeSymbol : ITypeSymbol
/// If this type is not a tuple, then returns default.
/// </summary>
ImmutableArray<IFieldSymbol> TupleElements { get; }

ImmutableArray<string> TupleElementNames { get; }
}
}
6 changes: 6 additions & 0 deletions src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End Get
End Property

Private ReadOnly Property INamedTypeSymbol_TupleElementNames As ImmutableArray(Of String) Implements INamedTypeSymbol.TupleElementNames
Get
Return TupleElementNames
End Get
End Property

Private ReadOnly Property INamedTypeSymbol_TupleUnderlyingType As INamedTypeSymbol Implements INamedTypeSymbol.TupleUnderlyingType
Get
Return TupleUnderlyingType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Program

<WpfFact>
<Trait(Traits.Feature, Traits.Features.ReferenceHighlighting)>
Public Async Function TestVerifyHighlightsForTupleElement() As Task
Public Async Function TestVerifyHighlightsForInferredTupleElement() As Task
Await VerifyHighlightsAsync(
<Workspace>
<Project Language="C#" CommonReferences="true">
Expand All @@ -73,8 +73,8 @@ class Program
static void Main(int {|Definition:Alice|})
{
var x = ({|Definition:{|Reference:Al$$ice|}|}, Bob: 2);
var y = ({|Reference:Alice|}:1, Bob: 2); // PROTOTYPE I'm not entirely sure why this gets highlighted
var z = ({|Reference:Alice|}:1, Carol: 2); // PROTOTYPE I'm not entirely sure why this gets highlighted
var y = ({|Reference:Alice|}:1, Bob: 2);
var z = (Alice:1, Carol: 2);

var z = x.{|Reference:Alice|};
var z2 = x.{|Reference:Item1|};
Expand All @@ -96,9 +96,9 @@ class Program
{
static void Main(int Alice)
{
var x = (Alice, Bob: 2);
var x = (Alice, Bob: 2); // PROTOTYPE This probably should be highlighted, although the field name is inferred
var y = ({|Definition:Ali$$ce|}:1, Bob: 2);
var z = ({|Reference:Alice|}:1, Carol: 2); // PROTOTYPE seems strange this is highlighted, but not Alice on x
var z = (Alice:1, Carol: 2);

var z1 = x.{|Reference:Alice|};
var z2 = x.{|Reference:Item1|};
Expand All @@ -121,11 +121,11 @@ class Program
static void Main(int Alice)
{
var x = (Alice, Bob: 2);
var y = ({|Reference:Alice|}:1, Bob: 2);
var z = ({|Definition:Al$$ice|}:1, Carol: 2); // PROTOTYPE There is a bug in test infrastructure, which falsely fails this test
var y = (Alice:1, Bob: 2);
var z = ({|Definition:Al$$ice|}:1, Carol: 2);

var z1 = x.{|Reference:Alice|};
var z2 = x.{|Reference:Item1|};
var z1 = x.Alice;
var z2 = x.Item1;
}
}
</Document>
Expand All @@ -144,9 +144,9 @@ class Program
{
static void Main(int Alice)
{
var x = ({|Definition:Alice|}, Bob: 2); // PROTOTYPE I'm not entirely sure why this gets highlighted
var x = ({|Definition:Alice|}, Bob: 2);
var y = ({|Reference:Alice|}:1, Bob: 2);
var z = ({|Reference:Alice|}:1, Carol: 2);
var z = (Alice:1, Carol: 2);

var z1 = x.{|Reference:Al$$ice|};
var z2 = x.{|Reference:Item1|};
Expand All @@ -169,8 +169,8 @@ class Program
static void Main(int Alice)
{
var x = ({|Definition:Alice|}, Bob: 2);
var y = ({|Reference:Alice|}:1, Bob: 2); // PROTOTYPE I'm not entirely sure why this gets highlighted
var z = ({|Reference:Alice|}:1, Carol: 2); // PROTOTYPE I'm not entirely sure why this gets highlighted
var y = ({|Reference:Alice|}:1, Bob: 2);
var z = (Alice:1, Carol: 2);

var z1 = x.{|Reference:Alice|};
var z2 = x.{|Reference:Ite$$m1|};
Expand All @@ -196,7 +196,7 @@ class Program
var z = ({|Definition:{|Reference:Al$$ice|}|}, Carol: 2);

var z1 = x.Other;
var z2 = x.{|Reference:Item1|} // PROTOTYPE I'm not entirely sure why this gets highlighted;
var z2 = x.Item1;
}
}
</Document>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private static ISymbol WrapMember(ISymbol m, bool canImplementImplicitly, IDocum
public ImmutableArray<INamedTypeSymbol> Interfaces => _symbol.Interfaces;
public ImmutableArray<INamedTypeSymbol> AllInterfaces => _symbol.AllInterfaces;
public ImmutableArray<IFieldSymbol> TupleElements => _symbol.TupleElements;
public ImmutableArray<string> TupleElementNames => _symbol.TupleElementNames;

public ImmutableArray<CustomModifier> GetTypeArgumentCustomModifiers(int ordinal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected static async Task<ImmutableArray<ReferenceLocation>> FindReferencesInD
var symbolToMatch = symbolInfoToMatch.Symbol;
var symbolToMatchCompilation = model.Compilation;

if (SymbolFinder.OriginalSymbolsMatch(searchSymbol, symbolInfoToMatch.Symbol, solution, null, symbolToMatchCompilation, cancellationToken))
if (SymbolFinder.OriginalSymbolsMatch(searchSymbol, symbolToMatch, solution, null, symbolToMatchCompilation, cancellationToken))
{
return (matched: true, CandidateReason.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,21 @@ private bool HandleNamedTypesWorker(INamedTypeSymbol x, INamedTypeSymbol y, Dict
}
}

var xElementNames = x.TupleElementNames;
var yElementNames = y.TupleElementNames;
if (xElementNames.Length != yElementNames.Length)
{
return false;
}

for (int i = 0; i < xElementNames.Length; i++)
{
if (xElementNames[i] != yElementNames[i])
{
return false;
}
}

return true;
}

Expand Down

0 comments on commit a75b2be

Please sign in to comment.