An unexpected exception is thrown by System.Linq.Expressions.Expression.ValidateUserDefinedConditionalLogicOperator when nullable value types are involved

Open
#115,674 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp
Domain
backend

Research direction

Start with System.Linq.Expressions.Expression.ValidateUserDefinedConditionalLogicOperator and the AndAlso and OrElse factory paths, then review the linked Roslyn issue for the nullable value type reproduction. Determine the required behavior for creating, interpreting, and compiling these trees, including the proposed True/False operator handling; done means the reproduction succeeds without the unexpected exception.

Written by the indexing model from the issue text.

Description

area-System.Linq.Expressions untriaged
Description

See:

I assume both AndAlso and OrElse factories are affected.

It is quite possible that if creation of such trees will be allowed, expression trees interpretation and compilation might need fixing as well.

Reproduction Steps

See above

Expected behavior

It should be possible to create, interpret and compile+execute such trees

Actual behavior
System.ArgumentException: The user-defined operator method 'op_BitwiseAnd' for operator 'AndAlso' must have associated boolean True and False operators.
   at System.Linq.Expressions.Expression.ValidateUserDefinedConditionalLogicOperator(ExpressionType nodeType, Type left, Type right, MethodInfo method)
   at System.Linq.Expressions.Expression.AndAlso(Expression left, Expression right, MethodInfo method)
Regression?

Unlikely

Known Workarounds

None known at the moment

Configuration

No response

Other information

I think it will be good to add an overload that explicitly takes MethodInfo for boolean True/False operator. And having a conversion lambda for the argument wouldn't hurt, that is if we would want to support extension operators.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.