fsharp
fsharp copied to clipboard
`LeafExpressionConverter.EvaluateQuotation` fails to handle some cases
Repro steps and actual behavior
FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.EvaluateQuotation raises a NotSupportedException when the quotation contains sequencing or variable/property/field mutation:
let eval = LeafExpressionConverter.EvaluateQuotation
eval <@ a; b @>
eval <@ a <- b @>
eval <@ a.b <- c @>
// System.NotSupportedException: Could not convert the following F# Quotation to a LINQ Expression Tree
Also, when the quotation is of type unit and the compiled expression tree is of type System.Void (such as a void method call) or something else (a mutation), Linq raises an ArgumentException:
eval <@ System.Console.WriteLine("Hello, World") @>
// System.ArgumentException: Expression of type 'System.Void' cannot be used for return type 'Microsoft.FSharp.Core.Unit'
Expected behavior
The function should correctly compile the expression to Linq tree and execute in these cases.
Known workarounds
Avoid these problematic constructs in the quotation. For example, write a.set_b(c) instead of a.b <- c.