Skip to content

Commit 7a09e87

Browse files
authored
Fix #19156 (#19157)
1 parent da3cf8b commit 7a09e87

File tree

8 files changed

+1525
-40
lines changed

8 files changed

+1525
-40
lines changed

src/Compiler/Interactive/fsi.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,8 @@ type internal FsiDynamicCompiler
21312131
if tcConfig.printAst then
21322132
for input in declaredImpls do
21332133
fprintfn fsiConsoleOutput.Out "AST:"
2134-
fprintfn fsiConsoleOutput.Out "%+A" input
2134+
let layout = DebugPrint.implFileL input
2135+
fprintfn fsiConsoleOutput.Out "%s" (LayoutRender.showL layout)
21352136
#endif
21362137

21372138
diagnosticsLogger.AbortOnError(fsiConsoleOutput)

src/Compiler/TypedTree/TypedTreeOps.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11225,13 +11225,16 @@ let mkOptimizedRangeLoop (g: TcGlobals) (mBody, mFor, mIn, spInWhile) (rangeTy,
1122511225
| RangeCount.PossiblyOversize calc ->
1122611226
calc (fun count wouldOvf ->
1122711227
buildLoop count (fun mkBody ->
11228+
// mkBody creates expressions that may contain lambdas with unique stamps.
11229+
// We need to copy the expression for the second branch to avoid duplicate type names.
11230+
let mkBodyCopied idxVar loopVar = copyExpr g CloneAll (mkBody idxVar loopVar)
1122811231
mkCond
1122911232
DebugPointAtBinding.NoneAtInvisible
1123011233
mIn
1123111234
g.unit_ty
1123211235
wouldOvf
1123311236
(mkCountUpInclusive mkBody (tyOfExpr g count))
11234-
(mkCompGenLetIn mIn (nameof count) (tyOfExpr g count) count (fun (_, count) -> mkCountUpExclusive mkBody count))))
11237+
(mkCompGenLetIn mIn (nameof count) (tyOfExpr g count) count (fun (_, count) -> mkCountUpExclusive mkBodyCopied count))))
1123511238
)
1123611239

1123711240
let mkDebugPoint m expr =

tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let f0 f = [|for n in 1..10 do f (); yield n|]
1+
let f0 f = [|for n in 1..10 do f (); yield n|]
22
let f00 f g = [|for n in 1..10 do f (); g (); yield n|]
33
let f000 f = [|for n in 1..10 do f (); yield n; yield n + 1|]
44
let f0000 () = [|for n in 1..10 do yield n|]
@@ -42,3 +42,8 @@ let f29 f g = [|let y = f () in let z = g () in for x in 1..2..10 -> x + y + z|]
4242
let f30 f g = [|let y = f () in g (); for x in 1..2..10 -> x + y|]
4343
let f31 f g = [|f (); g (); for x in 1..2..10 -> x|]
4444
let f32 f g = [|f (); let y = g () in for x in 1..2..10 -> x + y|]
45+
46+
// https://github.com/dotnet/fsharp/issues/19156
47+
let f33 (start : int) (finish : int) f = [|for _ in start..finish -> id id ()|]
48+
let f34 (start : int64) (finish : int64) f = [|for _ in start..finish -> id id ()|]
49+
let f35 (start : uint64) (finish : uint64) f = [|for _ in start..finish -> id id ()|]

tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs.il.bsl

Lines changed: 762 additions & 0 deletions
Large diffs are not rendered by default.

tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let f0 f = [for n in 1..10 do f (); yield n]
1+
let f0 f = [for n in 1..10 do f (); yield n]
22
let f00 f g = [|for n in 1..10 do f (); g (); yield n|]
33
let f000 f = [for n in 1..10 do f (); yield n; yield n + 1]
44
let f0000 () = [for n in 1..10 do yield n]
@@ -42,3 +42,8 @@ let f29 f g = [let y = f () in let z = g () in for x in 1..2..10 -> x + y + z]
4242
let f30 f g = [let y = f () in g (); for x in 1..2..10 -> x + y]
4343
let f31 f g = [f (); g (); for x in 1..2..10 -> x]
4444
let f32 f g = [f (); let y = g () in for x in 1..2..10 -> x + y]
45+
46+
// https://github.com/dotnet/fsharp/issues/19156
47+
let f33 (start : int) (finish : int) f = [for _ in start..finish -> id id ()]
48+
let f34 (start : int64) (finish : int64) f = [for _ in start..finish -> id id ()]
49+
let f35 (start : uint64) (finish : uint64) f = [for _ in start..finish -> id id ()]

tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs.il.bsl

Lines changed: 703 additions & 36 deletions
Large diffs are not rendered by default.

tests/FSharp.Compiler.ComponentTests/Language/RegressionTests.fs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,37 @@ type TestItemSeq =
1919
|> compile
2020
|> withErrorCodes [39]
2121
|> ignore
22+
23+
// https://github.com/dotnet/fsharp/issues/19156
24+
[<Fact>]
25+
let ``Generic list comprehension with nested lambda should not cause duplicate entry in type index table``() =
26+
FSharp """
27+
module Test
28+
open System
29+
30+
let f (start: DateTime) (stop: DateTime) (input: (DateTime * 'a) list) =
31+
[
32+
for i in start.Ticks .. stop.Ticks ->
33+
input |> List.where (fun (k, v) -> true)
34+
]
35+
"""
36+
|> compile
37+
|> shouldSucceed
38+
|> ignore
39+
40+
// https://github.com/dotnet/fsharp/issues/19156
41+
[<Fact>]
42+
let ``Generic array comprehension with nested lambda should not cause duplicate entry in type index table``() =
43+
FSharp """
44+
module Test
45+
open System
46+
47+
let f (start: DateTime) (stop: DateTime) (input: (DateTime * 'a) list) =
48+
[|
49+
for i in start.Ticks .. stop.Ticks ->
50+
input |> List.where (fun (k, v) -> true)
51+
|]
52+
"""
53+
|> compile
54+
|> shouldSucceed
55+
|> ignore

tests/walkthroughs/DebugStepping/TheBigFileOfDebugStepping.fsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ let ListExpressionSteppingTest8 () =
190190
yield x
191191
]
192192

193+
// Test case from https://github.com/dotnet/fsharp/issues/19156
194+
let ListExpressionSteppingTest9 () =
195+
[
196+
for i in DateTime.Now.Ticks .. DateTime.Now.Ticks + 1L ->
197+
['a', 1] |> List.where (fun (k, v) -> true)
198+
]
199+
193200
let SeqExpressionSteppingTest1 () =
194201
seq { yield 1 }
195202

@@ -842,6 +849,7 @@ ListExpressionSteppingTest5()
842849
ListExpressionSteppingTest6()
843850
ListExpressionSteppingTest7()
844851
ListExpressionSteppingTest8()
852+
ListExpressionSteppingTest9 () |> ignore
845853
SeqExpressionSteppingTest1()|> Seq.length
846854
SeqExpressionSteppingTest2()|> Seq.length
847855
SeqExpressionSteppingTest3()|> Seq.length

0 commit comments

Comments
 (0)