Skip to content

Commit 4e5f010

Browse files
committed
Check evaluation order
1 parent 4bf34c6 commit 4e5f010

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/fsharp/FSharp.Compiler.Unittests/SeqFusion.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type SeqFusionTestsModule() =
3131
member this.FusisonOfTwoMapsKeepsSideEffectOrder() =
3232
let list = List<string>()
3333
let data = ["hello"; "world"; "!"]
34-
let result = Seq.map (fun x -> x * 3) (Seq.map (fun y -> list.Add y; y.Length) data)
34+
let result = Seq.map (fun x -> list.Add(x.ToString()); x * 3) (Seq.map (fun y -> list.Add y; y.Length) data)
3535

3636
// seq is not evaluated yet
3737
Assert.areEqual 0 list.Count
3838

3939
// evaluate it
4040
Assert.areEqual [15; 15; 3] (Seq.toList result)
4141

42-
Assert.areEqual data (Seq.toList list)
42+
Assert.areEqual ["hello"; "5"; "world"; "5"; "!"; "1"] (Seq.toList list)

src/fsharp/Optimizer.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,9 +2619,9 @@ and OptimizeApplication cenv env (f0,f0ty,tyargs,args,m) =
26192619
| _ ->
26202620
match expr' with
26212621
// Rewrite Seq.map f (Seq.map g) xs into Seq.map (fun x -> f(g x)) xs
2622-
| Expr.App(Expr.Val(valRef,_,_) as outerSeqMap,ttype1,[_;t12],
2622+
| Expr.App(Expr.Val(valRef,_,_) as outerSeqMap,ttype1,[_;fOutType],
26232623
[(Expr.Lambda(_,None,None,_,_,m1,fRetType) as f)
2624-
Expr.App(Expr.Val(valRef2,_,_),_,[t21;_],
2624+
Expr.App(Expr.Val(valRef2,_,_),_,[gInType;_],
26252625
[Expr.Lambda(_,None,None,gVals,g,_,gRetType)
26262626
rest],_)],m2) when
26272627
valRefEq cenv.g valRef cenv.g.seq_map_vref &&
@@ -2630,7 +2630,7 @@ and OptimizeApplication cenv env (f0,f0ty,tyargs,args,m) =
26302630
let newApp = Expr.App(f,TType_fun(gRetType, fRetType),[],[g],m2)
26312631

26322632
let reduced =
2633-
Expr.App(outerSeqMap,ttype1,[t21;t12],
2633+
Expr.App(outerSeqMap,ttype1,[gInType;fOutType],
26342634
[Expr.Lambda (newUnique(), None, None, gVals, newApp, m1, gRetType)
26352635
rest],m2)
26362636

0 commit comments

Comments
 (0)