Skip to content
Open

Patch 1 #19100

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
45 changes: 45 additions & 0 deletions src/FSharp.Core/Linq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,46 @@ module LeafExpressionConverter =
let convType = lambdaTy.MakeGenericType tyargs
let convDelegate = Expression.Lambda(convType, bodyP, [| vP |]) |> asExpr
Expression.Call(typeof<FuncConvert>, "ToFSharpFunc", tyargs, [| convDelegate |]) |> asExpr

| Sequential _ ->
let flattenNestedSeq = function
| Sequential(e1, e2) -> seq { e1; e2 }
| e -> Seq.singleton e
let exprs =
inp
|> flattenNestedSeq
|> Seq.map (ConvExprToLinqInContext env)
|> Array.ofSeq
Expression.Block(exprs) |> asExpr

| VarSet(v, e) ->
let vP =
try
Map.find v env.varEnv
with
| :? KeyNotFoundException -> invalidOp ("The variable '"+ v.Name + "' was not found in the translation context'")
let eP = ConvExprToLinqInContext env e
Expression.Assign(vP, eP) |> asExpr

| PropertySet(objOpt, propInfo, args, e) ->
let coerceTo =
if objOpt.IsSome && FSharpType.IsUnion propInfo.DeclaringType && FSharpType.IsUnion propInfo.DeclaringType.BaseType then
Some propInfo.DeclaringType
else
None
let eP = ConvExprToLinqInContext env e
match args with
| [] ->
Expression.Assign(Expression.Property(ConvObjArg env objOpt coerceTo, propInfo), eP) |> asExpr
| _ ->
let argsP = ConvExprsToLinq env args
Expression.Call(ConvObjArg env objOpt coerceTo, propInfo.GetSetMethod(true), argsP) |> asExpr

| FieldSet(objOpt, fieldInfo, e) ->
let objP = ConvObjArg env objOpt None
let eP = ConvExprToLinqInContext env e
Expression.Assign(Expression.Field(objP, fieldInfo), eP) |> asExpr

| _ ->
failConvert inp

Expand Down Expand Up @@ -910,6 +950,11 @@ module LeafExpressionConverter =
| Value (obj, _) -> obj
| _ ->
let ty = e.Type
let e =
if ty = typeof<unit> then
Expr.Sequential(e, <@ () @>)
else
e
let e = Expr.NewDelegate (Expression.GetFuncType([|typeof<unit>; ty |]), [new Var("unit", typeof<unit>)], e)
let linqExpr = (ConvExprToLinq e:?> LambdaExpression)
let d = linqExpr.Compile ()
Expand Down
Loading