mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
C#: Handle some broken types in BMN.
This commit is contained in:
@@ -166,7 +166,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
// Create typerefs for constructed error types in case they are fully defined elsewhere.
|
||||
// We cannot use `!this.NeedsPopulation` because this would not be stable as it would depend on
|
||||
// the assembly that was being extracted at the time.
|
||||
private bool UsesTypeRef => Symbol.TypeKind == TypeKind.Error || SymbolEqualityComparer.Default.Equals(Symbol.OriginalDefinition, Symbol);
|
||||
private bool UsesTypeRef =>
|
||||
Symbol.TypeKind == TypeKind.Error ||
|
||||
SymbolEqualityComparer.Default.Equals(Symbol.OriginalDefinition, Symbol);
|
||||
|
||||
public override Type TypeRef => UsesTypeRef ? (Type)NamedTypeRef.Create(Context, Symbol) : this;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,22 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
symbol.ContainingType is not null && ConstructedOrParentIsConstructed(symbol.ContainingType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true in case we suspect this is broken type.
|
||||
/// </summary>
|
||||
/// <param name="symbol">Type symbol</param>
|
||||
private bool IsBrokenType(ITypeSymbol symbol)
|
||||
{
|
||||
if (!Context.ExtractionContext.IsStandalone || !symbol.FromSource())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// (1) public class { ... } is a broken type and doesn't have a name.
|
||||
// (2) public class var { ... } is a an allowed type, but it overrides the var keyword for all uses.
|
||||
// It is probably a better heuristic to treat it as a broken type.
|
||||
return string.IsNullOrEmpty(symbol.Name) || symbol.Name == "var";
|
||||
}
|
||||
|
||||
public Kinds.TypeKind GetTypeKind(Context cx, bool constructUnderlyingTupleType)
|
||||
{
|
||||
switch (Symbol.SpecialType)
|
||||
@@ -48,6 +64,9 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
if (Symbol.IsBoundNullable())
|
||||
return Kinds.TypeKind.NULLABLE;
|
||||
|
||||
if (IsBrokenType(Symbol))
|
||||
return Kinds.TypeKind.UNKNOWN;
|
||||
|
||||
switch (Symbol.TypeKind)
|
||||
{
|
||||
case TypeKind.Class: return Kinds.TypeKind.CLASS;
|
||||
|
||||
Reference in New Issue
Block a user