C#: Fix nullability warnings after .net 5 upgrade

This commit is contained in:
Tamas Vajk
2021-03-03 14:25:59 +01:00
parent 828e1f81ae
commit cfd8a87496
6 changed files with 9 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities
/// Gets the property symbol associated accessor `symbol`, or `null`
/// if there is no associated symbol.
/// </summary>
public static IPropertySymbol GetPropertySymbol(IMethodSymbol symbol)
public static IPropertySymbol? GetPropertySymbol(IMethodSymbol symbol)
{
// Usually, the property/indexer can be fetched from the associated symbol
if (symbol.AssociatedSymbol is IPropertySymbol prop)
@@ -29,7 +29,7 @@ namespace Semmle.Extraction.CSharp.Entities
/// <summary>
/// Gets the property symbol associated with this accessor.
/// </summary>
private IPropertySymbol PropertySymbol => GetPropertySymbol(Symbol);
private IPropertySymbol? PropertySymbol => GetPropertySymbol(Symbol);
public new Accessor OriginalDefinition => Create(Context, Symbol.OriginalDefinition);

View File

@@ -101,7 +101,7 @@ namespace Semmle.Extraction.CSharp.Entities
protected virtual T BodyDeclaringSymbol => Symbol;
public BlockSyntax Block
public BlockSyntax? Block
{
get
{
@@ -112,7 +112,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
}
public ExpressionSyntax ExpressionBody
public ExpressionSyntax? ExpressionBody
{
get
{

View File

@@ -86,7 +86,7 @@ namespace Semmle.Extraction.CSharp.Entities
}
}
private ConstructorDeclarationSyntax Syntax
private ConstructorDeclarationSyntax? Syntax
{
get
{
@@ -122,7 +122,7 @@ namespace Semmle.Extraction.CSharp.Entities
trapFile.Write(";constructor");
}
private ConstructorDeclarationSyntax GetSyntax() =>
private ConstructorDeclarationSyntax? GetSyntax() =>
Symbol.DeclaringSyntaxReferences.Select(r => r.GetSyntax()).OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
public override Microsoft.CodeAnalysis.Location? FullLocation => ReportingLocation;

View File

@@ -13,7 +13,7 @@ namespace Semmle.Extraction.CSharp.Entities
public static new Conversion Create(Context cx, IMethodSymbol symbol) =>
ConversionFactory.Instance.CreateEntityFromSymbol(cx, symbol);
public override Microsoft.CodeAnalysis.Location ReportingLocation
public override Microsoft.CodeAnalysis.Location? ReportingLocation
{
get
{

View File

@@ -83,7 +83,7 @@ namespace Semmle.Extraction.CSharp.Entities
if (block != null)
Statements.Block.Create(Context, block, this, 0);
else
Expression.Create(Context, expr, this, 0);
Expression.Create(Context, expr!, this, 0);
NumberOfLines(trapFile, BodyDeclaringSymbol, this);
});

View File

@@ -75,7 +75,7 @@ namespace Semmle.Extraction.CSharp
}
var versionInfo = FileVersionInfo.GetVersionInfo(SpecifiedCompiler);
if (!knownCompilerNames.TryGetValue(versionInfo.OriginalFilename, out var vendor))
if (!knownCompilerNames.TryGetValue(versionInfo.OriginalFilename ?? string.Empty, out var vendor))
{
SkipExtractionBecause("the compiler name is not recognised");
return;