Skip to content

Commit

Permalink
Fix Regression with quotations of List.sum on non-primitive type
Browse files Browse the repository at this point in the history
  • Loading branch information
Don Syme committed Oct 30, 2020
1 parent 886205d commit 6ff5101
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/fsharp/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,13 +1864,21 @@ let GenWitnessExpr amap g m (traitInfo: TraitConstraintInfo) argExprs =
let argTypes =
minfo.GetParamTypes(amap, m, methArgTys)
|> List.concat

// do not apply coercion to the 'receiver' argument
let receiverArgOpt, argExprs =
if minfo.IsInstance then
match argExprs with
| h :: t -> Some h, t
| argExprs -> None, argExprs
else None, argExprs

// For methods taking no arguments, 'argExprs' will be a single unit expression here
let argExprs =
match argTypes, argExprs with
| [], [_] -> []
| _ -> argExprs

let convertedArgs = (argExprs, argTypes) ||> List.map2 (fun expr expectedTy -> mkCoerceIfNeeded g expectedTy (tyOfExpr g expr) expr)
match receiverArgOpt with
| Some r -> r :: convertedArgs
Expand Down
18 changes: 18 additions & 0 deletions tests/fsharp/core/quotes/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3864,6 +3864,24 @@ module TestInlineQuotationOfAbsOperator =
| _ -> false)


module TestQuotationOfListSum =
type Point =
{ x: int; y: int }
static member Zero = { x=0; y=0 }
static member (+) (p1, p2) = { x= p1.x + p2.x; y = p1.y + p2.y }
let points = [{x=1; y=10}]

let q = <@ List.sum points @>

test "check List.sum"
(match q with
| CallWithWitnesses(None, minfo1, minfo2, [Value(f1,_); Value(f2,_)], [Value (v,_)]) ->
minfo1.Name = "Sum" &&
minfo2.Name = "Sum$W" &&
((v :?> Point list) = points) &&
(((f1 :?> (unit -> Point)) ()) = Point.Zero) &&
(((f2 :?> (Point -> Point -> Point)) {x=1;y=1} {x=1;y=2}) = {x=2;y=3})
| _ -> false)

#endif

Expand Down

0 comments on commit 6ff5101

Please sign in to comment.