mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Respect the context when extracting locations for type parameters and tuple typles.
This commit is contained in:
@@ -54,8 +54,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
// Note: symbol.Locations seems to be very inconsistent
|
||||
// about what locations are available for a tuple type.
|
||||
// Sometimes it's the source code, and sometimes it's empty.
|
||||
foreach (var l in Symbol.Locations)
|
||||
WriteLocationToTrap(trapFile.type_location, this, Context.CreateLocation(l));
|
||||
var locations = Context.GetLocations(Symbol);
|
||||
WriteLocationsToTrap(trapFile.type_location, this, locations);
|
||||
}
|
||||
|
||||
private readonly Lazy<Field?[]> tupleElementsLazy;
|
||||
|
||||
@@ -28,10 +28,8 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
|
||||
if (Context.ExtractLocation(Symbol))
|
||||
{
|
||||
foreach (var l in Symbol.Locations)
|
||||
{
|
||||
WriteLocationToTrap(trapFile.type_location, this, Context.CreateLocation(l));
|
||||
}
|
||||
var locations = Context.GetLocations(Symbol);
|
||||
WriteLocationsToTrap(trapFile.type_location, this, locations);
|
||||
}
|
||||
|
||||
if (IsSourceDeclaration)
|
||||
|
||||
@@ -554,6 +554,18 @@ namespace Semmle.Extraction.CSharp
|
||||
SymbolEqualityComparer.Default.Equals(symbol, symbol.OriginalDefinition) &&
|
||||
scope.InScope(symbol);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the locations of the symbol that are either
|
||||
/// (1) In assemblies.
|
||||
/// (2) In the current context.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol</param>
|
||||
/// <returns>List of locations</returns>
|
||||
public IEnumerable<Entities.Location> GetLocations(ISymbol symbol) =>
|
||||
symbol.Locations
|
||||
.Where(l => !l.IsInSource || IsLocationInContext(l))
|
||||
.Select(CreateLocation);
|
||||
|
||||
public bool IsLocationInContext(Location location) =>
|
||||
location.SourceTree == SourceTree;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user