Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static analysis: remove redundant nullable warning suppression #26941

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CandidateNamingService : ICandidateNamingService
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string GenerateCandidateIdentifier(DatabaseTable originalTable)
=> GenerateCandidateIdentifier(originalTable.Name!);
=> GenerateCandidateIdentifier(originalTable.Name);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -30,7 +30,7 @@ public virtual string GenerateCandidateIdentifier(DatabaseTable originalTable)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string GenerateCandidateIdentifier(DatabaseColumn originalColumn)
=> GenerateCandidateIdentifier(originalColumn.Name!);
=> GenerateCandidateIdentifier(originalColumn.Name);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ private static void CheckOutputFiles(

if (File.Exists(fullPath))
{
existingFiles.Add(path!);
existingFiles.Add(path);

if (File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly))
{
readOnlyFiles.Add(path!);
readOnlyFiles.Add(path);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public virtual SavedModelFiles Save(

Directory.CreateDirectory(outputDir);

var contextPath = Path.GetFullPath(Path.Combine(outputDir, scaffoldedModel.ContextFile!.Path));
var contextPath = Path.GetFullPath(Path.Combine(outputDir, scaffoldedModel.ContextFile.Path));
Directory.CreateDirectory(Path.GetDirectoryName(contextPath)!);
File.WriteAllText(contextPath, scaffoldedModel.ContextFile.Code, Encoding.UTF8);

Expand All @@ -155,7 +155,7 @@ private static void CheckOutputFiles(
bool overwriteFiles)
{
var paths = scaffoldedModel.AdditionalFiles.Select(f => f.Path).ToList();
paths.Insert(0, scaffoldedModel.ContextFile!.Path);
paths.Insert(0, scaffoldedModel.ContextFile.Path);

var existingFiles = new List<string>();
var readOnlyFiles = new List<string>();
Expand All @@ -165,11 +165,11 @@ private static void CheckOutputFiles(

if (File.Exists(fullPath))
{
existingFiles.Add(path!);
existingFiles.Add(path);

if (File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly))
{
readOnlyFiles.Add(path!);
readOnlyFiles.Add(path);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& methodCallExpression.Arguments.Count == 1)
{
var left = Visit(methodCallExpression.Object);
var right = Visit(methodCallExpression.Arguments[0])!;
var right = Visit(methodCallExpression.Arguments[0]);

if (TryRewriteEntityEquality(
ExpressionType.Equal,
Expand Down Expand Up @@ -541,8 +541,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
methodCallExpression.Arguments[0], methodCallExpression.Arguments[1]));
}

var left = Visit(methodCallExpression.Arguments[0])!;
var right = Visit(methodCallExpression.Arguments[1])!;
var left = Visit(methodCallExpression.Arguments[0]);
var right = Visit(methodCallExpression.Arguments[1]);

if (TryRewriteEntityEquality(
ExpressionType.Equal,
Expand All @@ -565,8 +565,8 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
else if (method.IsGenericMethod
&& method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains))
{
var enumerable = Visit(methodCallExpression.Arguments[0])!;
var item = Visit(methodCallExpression.Arguments[1])!;
var enumerable = Visit(methodCallExpression.Arguments[0]);
var item = Visit(methodCallExpression.Arguments[1]);

if (TryRewriteContainsEntity(
enumerable,
Expand All @@ -588,7 +588,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
&& method.IsContainsMethod())
{
var enumerable = Visit(methodCallExpression.Object);
var item = Visit(methodCallExpression.Arguments[0])!;
var item = Visit(methodCallExpression.Arguments[0]);

if (TryRewriteContainsEntity(
enumerable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public virtual Expression Translate(InMemoryQueryExpression queryExpression, Exp

_queryExpression = null!;
_projectionMembers.Clear();
result = MatchTypes(result!, expression.Type);
result = MatchTypes(result, expression.Type);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public InMemoryQueryExpression(IEntityType entityType)
var discriminatorProperty = entityType.FindDiscriminatorProperty();
if (discriminatorProperty != null)
{
var keyValueComparer = discriminatorProperty.GetKeyValueComparer()!;
var keyValueComparer = discriminatorProperty.GetKeyValueComparer();
foreach (var derivedEntityType in entityType.GetDerivedTypes())
{
var entityCheck = derivedEntityType.GetConcreteDerivedTypesInclusive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public static IEnumerable<IReadOnlySequence> GetSequences(this IReadOnlyModel mo
/// <returns>The new <see cref="IMutableDbFunction" />.</returns>
public static IMutableDbFunction AddDbFunction(this IMutableModel model, MethodInfo methodInfo)
=> DbFunction.AddDbFunction(
model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit)!;
model, Check.NotNull(methodInfo, nameof(methodInfo)), ConfigurationSource.Explicit);

/// <summary>
/// Creates a function mapped to the given method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DbFunctionParameterBuilder : IInfrastructure<IConventionDbFunctionP
[EntityFrameworkInternal]
public DbFunctionParameterBuilder(IMutableDbFunctionParameter parameter)
{
Builder = ((DbFunctionParameter)parameter).Builder!;
Builder = ((DbFunctionParameter)parameter).Builder;
}

private InternalDbFunctionParameterBuilder Builder { [DebuggerStepThrough] get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public virtual InternalDbFunctionParameterBuilder HasParameter(string name, Conf
RelationalStrings.DbFunctionInvalidParameterName(Metadata.MethodInfo?.DisplayName(), name));
}

return parameter.Builder!;
return parameter.Builder;
}

IConventionDbFunction IConventionDbFunctionBuilder.Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ private static StoreFunction GetOrCreateStoreFunction(IRuntimeDbFunction dbFunct
var storeFunction = (StoreFunction?)dbFunction.StoreFunction;
if (storeFunction == null)
{
var parameterTypes = dbFunction.Parameters.Select(p => p.StoreType!).ToArray();
var parameterTypes = dbFunction.Parameters.Select(p => p.StoreType).ToArray();
storeFunction = (StoreFunction?)model.FindFunction(dbFunction.Name, dbFunction.Schema, parameterTypes);
if (storeFunction == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public StoreFunctionParameter(
{
Function = function;
Name = parameter.Name;
Type = parameter.StoreType!;
Type = parameter.StoreType;
DbFunctionParameters = new List<IDbFunctionParameter> { parameter };
parameter.StoreFunctionParameter = this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
_selectExpression = null!;
_projectionMembers.Clear();

result = MatchTypes(result!, expression.Type);
result = MatchTypes(result, expression.Type);

return result;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override ElementInit VisitElementInit(ElementInit elementInit)
=> elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e)!, e.Type)));
=> elementInit.Update(elementInit.Arguments.Select(e => MatchTypes(Visit(e), e.Type)));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -454,7 +454,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
for (var i = 0; i < methodCallExpression.Arguments.Count; i++)
{
var argument = methodCallExpression.Arguments[i];
arguments[i] = MatchTypes(Visit(argument)!, argument.Type);
arguments[i] = MatchTypes(Visit(argument), argument.Type);
}

Expression updatedMethodCallExpression = methodCallExpression.Update(
Expand Down Expand Up @@ -521,7 +521,7 @@ protected override Expression VisitNew(NewExpression newExpression)
_projectionMembers.Pop();
}

newArguments[i] = MatchTypes(visitedArgument!, argument.Type);
newArguments[i] = MatchTypes(visitedArgument, argument.Type);
}

return newExpression.Update(newArguments);
Expand All @@ -534,7 +534,7 @@ protected override Expression VisitNew(NewExpression newExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitNewArray(NewArrayExpression newArrayExpression)
=> newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e)!, e.Type)));
=> newArrayExpression.Update(newArrayExpression.Expressions.Select(e => MatchTypes(Visit(e), e.Type)));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private sealed class ColumnExpressionFindingExpressionVisitor : ExpressionVisito
switch (expression)
{
case ColumnExpression columnExpression:
var tableAlias = columnExpression.TableAlias!;
var tableAlias = columnExpression.TableAlias;
if (_columnReferenced!.ContainsKey(tableAlias))
{
_columnReferenced[tableAlias] ??= new HashSet<string>();
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Storage/RelationalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public virtual RelationalDataReader ExecuteReader(RelationalCommandParameterObje
? interceptionResult.Result
: command.ExecuteReader();

reader = logger!.CommandReaderExecuted(
reader = logger.CommandReaderExecuted(
connection,
command,
context,
Expand Down Expand Up @@ -580,7 +580,7 @@ public virtual async Task<RelationalDataReader> ExecuteReaderAsync(
? interceptionResult.Result
: await command.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false);

reader = await logger!.CommandReaderExecutedAsync(
reader = await logger.CommandReaderExecutedAsync(
connection,
command,
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ protected override bool IsHandledByConvention(IModel model, IAnnotation annotati
(name, schema) switch
{
(null, null) => Array.Empty<object>(),
(_, null) => new object[] { name! },
_ => new object[] { name!, schema! }
(_, null) => new object[] { name },
_ => new object[] { name!, schema }
});

case SqlServerValueGenerationStrategy.None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ bool TryGetPrimaryKey(
var columnName = dataRecord.GetValueOrDefault<string>("column_name");
var column = table.Columns.FirstOrDefault(c => c.Name == columnName)
?? table.Columns.FirstOrDefault(
c => c.Name!.Equals(columnName, StringComparison.OrdinalIgnoreCase));
c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));

if (column is null)
{
Expand Down Expand Up @@ -1069,7 +1069,7 @@ bool TryGetUniqueConstraint(
var columnName = dataRecord.GetValueOrDefault<string>("column_name");
var column = table.Columns.FirstOrDefault(c => c.Name == columnName)
?? table.Columns.FirstOrDefault(
c => c.Name!.Equals(columnName, StringComparison.OrdinalIgnoreCase));
c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));

if (column is null)
{
Expand Down Expand Up @@ -1117,7 +1117,7 @@ bool TryGetIndex(

var column = table.Columns.FirstOrDefault(c => c.Name == columnName)
?? table.Columns.FirstOrDefault(
c => c.Name!.Equals(columnName, StringComparison.OrdinalIgnoreCase));
c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));

if (column is null)
{
Expand Down Expand Up @@ -1227,19 +1227,19 @@ FROM [sys].[foreign_keys] AS [f]
var columnName = dataRecord.GetValueOrDefault<string>("column_name");
var column = table.Columns.FirstOrDefault(c => c.Name == columnName)
?? table.Columns.FirstOrDefault(
c => c.Name!.Equals(columnName, StringComparison.OrdinalIgnoreCase));
c => c.Name.Equals(columnName, StringComparison.OrdinalIgnoreCase));
Check.DebugAssert(column != null, "column is null.");

var principalColumnName = dataRecord.GetValueOrDefault<string>("referenced_column_name");
var principalColumn = foreignKey.PrincipalTable.Columns.FirstOrDefault(c => c.Name == principalColumnName)
?? foreignKey.PrincipalTable.Columns.FirstOrDefault(
c => c.Name!.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase));
c => c.Name.Equals(principalColumnName, StringComparison.OrdinalIgnoreCase));
if (principalColumn == null)
{
invalid = true;
_logger.ForeignKeyPrincipalColumnMissingWarning(
fkName!,
DisplayName(table.Schema, table.Name!),
DisplayName(table.Schema, table.Name),
principalColumnName!,
DisplayName(principalTableSchema, principalTableName));
break;
Expand All @@ -1255,7 +1255,7 @@ FROM [sys].[foreign_keys] AS [f]
{
_logger.ReflexiveConstraintIgnored(
foreignKey.Name!,
DisplayName(table.Schema, table.Name!));
DisplayName(table.Schema, table.Name));
}
else
{
Expand All @@ -1267,7 +1267,7 @@ FROM [sys].[foreign_keys] AS [f]
{
_logger.DuplicateForeignKeyConstraintIgnored(
foreignKey.Name!,
DisplayName(table.Schema, table.Name!),
DisplayName(table.Schema, table.Name),
duplicated.Name!);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private string GetTypeNameForCopy(IProperty property)
&& (typeName.Equals("rowversion", StringComparison.OrdinalIgnoreCase)
|| typeName.Equals("timestamp", StringComparison.OrdinalIgnoreCase))
? property.IsNullable ? "varbinary(8)" : "binary(8)"
: typeName!;
: typeName;
}

// ReSharper disable once ParameterTypeCanBeEnumerable.Local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public SqliteMathTranslator(ISqlExpressionFactory sqlExpressionFactory)
List<SqlExpression>? newArguments = null;
if (sqlFunctionName == "max" || sqlFunctionName == "max")
{
typeMapping = ExpressionExtensions.InferTypeMapping(arguments![0]!, arguments[1]!);
typeMapping = ExpressionExtensions.InferTypeMapping(arguments[0], arguments[1]);
newArguments = new List<SqlExpression>
{
_sqlExpressionFactory.ApplyTypeMapping(arguments[0], typeMapping),
Expand Down
Loading