Skip to content

Commit a263eca

Browse files
authored
Merge pull request #46315 from dotnet/merges/release/dev16.7-to-release/dev16.8-preview1
Merge release/dev16.7 to release/dev16.8-preview1
2 parents cbb5cf1 + 75af7e1 commit a263eca

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed

src/Workspaces/Core/Portable/Remote/RemoteArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public async Task<ISymbol> TryRehydrateAsync(
114114
try
115115
{
116116
throw new InvalidOperationException(
117-
$"We should always be able to resolve a symbol back on the host side:\r\n{SymbolKeyData}\r\n{failureReason}");
117+
$"We should always be able to resolve a symbol back on the host side:\r\n{project.Name}\r\n{SymbolKeyData}\r\n{failureReason}");
118118
}
119119
catch (Exception ex) when (FatalError.ReportWithoutCrash(ex))
120120
{

src/Workspaces/Core/Portable/SymbolKey/SymbolKey.BodyLevelSymbolKey.cs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,22 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string? fa
132132
}
133133

134134
// First check if we can recover the symbol just through the original location.
135-
foreach (var loc in locations)
135+
136+
string? totalFailureReason = null;
137+
for (var i = 0; i < locations.Count; i++)
136138
{
137-
var resolutionOpt = reader.ResolveLocation(loc);
138-
if (resolutionOpt.HasValue)
139+
var loc = locations[i];
140+
141+
if (!TryResolveLocation(loc, i, out var resolution, out var reason))
139142
{
140-
var resolution = resolutionOpt.Value;
141-
var symbol = resolution.GetAnySymbol();
142-
if (symbol?.Kind == kind &&
143-
SymbolKey.Equals(reader.Compilation, name, symbol.Name))
144-
{
145-
failureReason = null;
146-
return resolution;
147-
}
143+
totalFailureReason = totalFailureReason == null
144+
? $"({reason})"
145+
: $"({totalFailureReason} -> {reason})";
146+
continue;
148147
}
148+
149+
failureReason = null;
150+
return resolution;
149151
}
150152

151153
// Couldn't recover. See if we can still find a match across the textual drift.
@@ -162,8 +164,42 @@ public static SymbolKeyResolution Resolve(SymbolKeyReader reader, out string? fa
162164
}
163165
}
164166

165-
failureReason = $"({nameof(BodyLevelSymbolKey)} '{name}' not found)";
167+
failureReason = $"({nameof(BodyLevelSymbolKey)} '{name}' not found -> {totalFailureReason})";
166168
return default;
169+
170+
bool TryResolveLocation(Location loc, int index, out SymbolKeyResolution resolution, out string? reason)
171+
{
172+
var resolutionOpt = reader.ResolveLocation(loc);
173+
if (resolutionOpt == null)
174+
{
175+
reason = $"location {index} failed to resolve";
176+
resolution = default;
177+
return false;
178+
}
179+
180+
resolution = resolutionOpt.Value;
181+
var symbol = resolution.GetAnySymbol();
182+
if (symbol == null)
183+
{
184+
reason = $"location {index} did not produce any symbol";
185+
return false;
186+
}
187+
188+
if (symbol.Kind != kind)
189+
{
190+
reason = $"location {index} did not match kind: {symbol.Kind} != {kind}";
191+
return false;
192+
}
193+
194+
if (!SymbolKey.Equals(reader.Compilation, name, symbol.Name))
195+
{
196+
reason = $"location {index} did not match name: {symbol.Name} != {name}";
197+
return false;
198+
}
199+
200+
reason = null;
201+
return true;
202+
}
167203
}
168204

169205
private static IEnumerable<(ISymbol symbol, int ordinal)> EnumerateSymbols(

src/Workspaces/Core/Portable/SymbolKey/SymbolKey.SymbolKeyReader.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public PooledArrayBuilder<T> ReadArray<T>(ReadFunction<T> readFunction, out stri
202202
var reason = $"element {i} failed {elementFailureReason}";
203203
totalFailureReason = totalFailureReason == null
204204
? $"({reason})"
205-
: $"(totalFailureReason -> {reason})";
205+
: $"({totalFailureReason} -> {reason})";
206206
}
207207
}
208208

@@ -538,20 +538,26 @@ public Location ReadLocation(out string failureReason)
538538
}
539539

540540
var kind = (LocationKind)ReadInteger();
541-
if (kind == LocationKind.SourceFile)
541+
if (kind == LocationKind.None)
542+
{
543+
failureReason = null;
544+
return Location.None;
545+
}
546+
else if (kind == LocationKind.SourceFile)
542547
{
543548
var filePath = ReadString();
544549
var start = ReadInteger();
545550
var length = ReadInteger();
546551

547-
// The syntax tree can be null if we're resolving this location in a compilation
548-
// that does not contain this file. In this case, just map this location to None.
549552
var syntaxTree = GetSyntaxTree(filePath);
550-
if (syntaxTree != null)
553+
if (syntaxTree == null)
551554
{
552-
failureReason = null;
553-
return Location.Create(syntaxTree, new TextSpan(start, length));
555+
failureReason = $"({nameof(ReadLocation)} failed -> '{filePath}' not in compilation)";
556+
return null;
554557
}
558+
559+
failureReason = null;
560+
return Location.Create(syntaxTree, new TextSpan(start, length));
555561
}
556562
else if (kind == LocationKind.MetadataFile)
557563
{
@@ -579,10 +585,14 @@ public Location ReadLocation(out string failureReason)
579585
}
580586
}
581587
}
582-
}
583588

584-
failureReason = null;
585-
return Location.None;
589+
failureReason = null;
590+
return Location.None;
591+
}
592+
else
593+
{
594+
throw ExceptionUtilities.UnexpectedValue(kind);
595+
}
586596
}
587597

588598
public SymbolKeyResolution? ResolveLocation(Location location)

0 commit comments

Comments
 (0)