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

Annotate IsNiladic for nullability on Arguments #23409

Merged
1 commit merged into from
Nov 20, 2020
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
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Query/QuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction
if (!sqlFunctionExpression.IsNiladic)
{
_relationalCommandBuilder.Append("(");
GenerateList(sqlFunctionExpression.Arguments!, e => Visit(e));
GenerateList(sqlFunctionExpression.Arguments, e => Visit(e));
_relationalCommandBuilder.Append(")");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using CA = System.Diagnostics.CodeAnalysis;

#nullable enable
namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
Expand All @@ -22,7 +23,6 @@ namespace Microsoft.EntityFrameworkCore.Query.SqlExpressions
/// not used in application code.
/// </para>
/// </summary>
// TODO - NULLABLE for C# 9 (MemberNotNullIf on IsNiladic)
public class SqlFunctionExpression : SqlExpression
{
/// <summary>
Expand Down Expand Up @@ -231,6 +231,7 @@ private SqlFunctionExpression(
/// <summary>
/// A bool value indicating if the function is niladic.
/// </summary>
[CA.MemberNotNullWhen(false, nameof(Arguments), nameof(ArgumentsPropagateNullability))]
public virtual bool IsNiladic { get; }

/// <summary>
Expand Down Expand Up @@ -276,7 +277,7 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
SqlExpression[]? arguments = default;
if (!IsNiladic)
{
arguments = new SqlExpression[Arguments!.Count];
arguments = new SqlExpression[Arguments.Count];
for (var i = 0; i < arguments.Length; i++)
{
arguments[i] = (SqlExpression)visitor.Visit(Arguments[i]);
Expand Down Expand Up @@ -367,7 +368,7 @@ protected override void Print(ExpressionPrinter expressionPrinter)
if (!IsNiladic)
{
expressionPrinter.Append("(");
expressionPrinter.VisitCollection(Arguments!);
expressionPrinter.VisitCollection(Arguments);
expressionPrinter.Append(")");
}
}
Expand All @@ -381,6 +382,7 @@ public override bool Equals(object? obj)

private bool Equals(SqlFunctionExpression sqlFunctionExpression)
=> base.Equals(sqlFunctionExpression)
&& IsNiladic == sqlFunctionExpression.IsNiladic
&& Name == sqlFunctionExpression.Name
&& Schema == sqlFunctionExpression.Schema
&& ((Instance == null && sqlFunctionExpression.Instance == null)
Expand Down
5 changes: 2 additions & 3 deletions src/EFCore.Relational/Query/SqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ protected virtual SqlExpression VisitSqlFunction(
return sqlFunctionExpression.Update(instance, sqlFunctionExpression.Arguments);
}

var arguments = new SqlExpression[sqlFunctionExpression.Arguments!.Count];
var arguments = new SqlExpression[sqlFunctionExpression.Arguments.Count];
for (var i = 0; i < arguments.Length; i++)
{
arguments[i] = Visit(sqlFunctionExpression.Arguments[i], out _);
Expand Down Expand Up @@ -1687,8 +1687,7 @@ private SqlExpression ProcessNullNotNull(SqlUnaryExpression sqlUnaryExpression,
nullabilityPropagationElements.Add(sqlFunctionExpression.Instance);
}

if (sqlFunctionExpression.Arguments != null
&& sqlFunctionExpression.ArgumentsPropagateNullability != null)
if (!sqlFunctionExpression.IsNiladic)
{
for (var i = 0; i < sqlFunctionExpression.Arguments.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ protected override Expression VisitSqlFunction(SqlFunctionExpression sqlFunction
SqlExpression[]? arguments = default;
if (!sqlFunctionExpression.IsNiladic)
{
arguments = new SqlExpression[sqlFunctionExpression.Arguments!.Count];
arguments = new SqlExpression[sqlFunctionExpression.Arguments.Count];
for (var i = 0; i < arguments.Length; i++)
{
arguments[i] = (SqlExpression)Visit(sqlFunctionExpression.Arguments[i]);
Expand Down