FSharp.Quotations.Evaluator
FSharp.Quotations.Evaluator copied to clipboard
Binary operator is not defined for System.Byte and System.Byte
Repro steps
The following code throws an exception: case 1:
QuotationEvaluator.Evaluate <@ fun (x: byte) (y: byte) -> x + y @>
case 2:
QuotationEvaluator.Evaluate <@ fun (x: byte) (y: byte) -> x * y @>
Actual behavior
case 1:
Unhandled exception. System.InvalidOperationException: The binary operator Add is not defined for the types 'System.Byte' and 'System.Byte'.
at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.Add(Expression left, Expression right, MethodInfo method)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr@245-14.Invoke(Tuple`2 tupledArg)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.binary@195[a](ConvEnv env, FSharpExpr x1, FSharpExpr x2, FSharpFunc`2 f)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr(ConvEnv env, FSharpOption`1 letrec, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.ConvExpr(ConvEnv env, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr(ConvEnv env, FSharpOption`1 letrec, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.ConvExpr(ConvEnv env, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.Conv[a](a e, Boolean eraseEquality)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.CompileImpl[a](a e, Boolean eraseEquality)
at FSharp.Quotations.Evaluator.QuotationEvaluator.Evaluate[T](FSharpExpr`1 e)
case 2:
Unhandled exception. System.InvalidOperationException: The binary operator Multiply is not defined for the types 'System.Byte' and 'System.Byte'.
at System.Linq.Expressions.Expression.GetUserDefinedBinaryOperatorOrThrow(ExpressionType binaryType, String name, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.Multiply(Expression left, Expression right, MethodInfo method)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr@248-17.Invoke(Tuple`2 tupledArg)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.binary@195[a](ConvEnv env, FSharpExpr x1, FSharpExpr x2, FSharpFunc`2 f)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr(ConvEnv env, FSharpOption`1 letrec, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.ConvExpr(ConvEnv env, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.LetRecConvExpr(ConvEnv env, FSharpOption`1 letrec, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.ConvExpr(ConvEnv env, FSharpExpr inp)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.Conv[a](a e, Boolean eraseEquality)
at FSharp.Quotations.Evaluator.QuotationEvaluationTypes.CompileImpl[a](a e, Boolean eraseEquality)
at FSharp.Quotations.Evaluator.QuotationEvaluator.Evaluate[T](FSharpExpr`1 e)
Known workarounds
<@ fun (x: byte) (y: byte) ->
let xInt = int x
let yInt = int y
let res = xInt + yInt
byte res @>
Related information
- Windows 10
- FSharp.Quotations.Evaluator v2.1.0
- TargetFramework: net7.0