Skip to content

Operator '>' incompatible with operand types 'Instant?' and 'Instant?' #970

@neilbgr

Description

@neilbgr

According to the code on https://dotnetfiddle.net/wTSGW5 (EFCore, net9, NodaTime) comparing nullable Instant (Instant?) fails:

Unhandled exception. Operator '>' incompatible with operand types 'Instant?' and 'Instant?' (at index 6)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.CheckAndPromoteOperands(Type signatures, TokenId opId, String opName, Expression& left, Expression& right, Int32 errorPos) in ~\Parser\ExpressionParser.cs:line 2528
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator() in ~\Parser\ExpressionParser.cs:line 647
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator() in ~\Parser\ExpressionParser.cs:line 446
  ...

After reading source code, I've found a clue in IRelationalSignatures interface.
As temporary workaround, in a local fork, I've added a package ref to NodaTime and this few lines :

using NodaTime;
using System.Diagnostics.CodeAnalysis;

namespace System.Linq.Dynamic.Core.Parser.SupportedOperands;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
internal interface IRelationalSignatures : IArithmeticSignatures
{
    ...
    void F(Instant x, Instant y);
    void F(Instant? x, Instant? y);
}

I known is not the solution, but it works (!) and I need a workaround so I'll use this ugly patch while there is not good public solution.

So my question is: will it be possible to handle comparable types and, above all, comparable nullable types?

Thks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions