Closed nikolamilekic closed 5 months ago
I have smaller repro:
This is a way to transpose sequences:
let x: seq<seq<int>> = traverse ZipList (seq [seq [1;2]; seq [10;20]]) |> ZipList.run
// val x : seq<seq<int>> = seq [seq [1; 10]; seq [2; 20]]
but if we mistype x as seq<int>
:
let x: seq<int> = traverse ZipList (seq [seq [1;2]; seq [10;20]]) |> ZipList.run
Exception raised during pretty printing.
Please report this so it can be fixed.
Trace: System.InvalidCastException: Unable to cast object of type 'mkSeq@132[System.Collections.Generic.IEnumerable`1[System.Int32]]' to type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
at FSharp.Compiler.Interactive.Shell.Utilities.AnyToLayoutSpecialization`1.FSharp.Compiler.Interactive.Shell.Utilities.IAnyToLayoutCall.FsiAnyToLayout(FormatOptions options, Object o, Type ty) in F:\workspace\_work\1\s\src\fsharp\fsi\fsi.fs:line 88
at FSharp.Compiler.Interactive.Shell.FsiValuePrinter.PrintValue(FsiValuePrinterMode printMode, FormatOptions opts, Object x, Type ty) in F:\workspace\_work\1\s\src\fsharp\fsi\fsi.fs:line 408
val x : seq<int> =
and x
gets created !
I'm pretty much sure this behavior was not observed in previous version of the F# compiler but I can't confirm, as my old Visual Studio seems to be broken.
This seems to be fixed in current F# (version 8 at the moment of writing this). Your repro works now, I mean it actually fails, but with the proper error message, about using seq instead of list, which prompts you to apply the workaround you showed.
My repro also fails properly now, and x
is not created.
Closing this.
Description
sequence
does not work as expected due to a problem with type inference (compiler bug?).Repro steps
Expected behavior
A compiler error, or for
StateT.run test 0.0
to return Ok assequence
input is a non-empty collection.Actual behavior
StateT.run test 0.0
returns Error becauseoutput |> Seq.isEmpty
is true.Known workarounds
Changing the
Seq.map
call to aList.map
beforesequence
is called. Making this mistake is how I discovered this problem. Shouldn't the compiler protect me from these mistakes?Related information
The reason I believe this is triggering a compiler bug is that calling
GetType
onprojectsAndSprintIds
from withinissuesFunction
returns anIEnumerator
, and the declared type of the argument isList<int * int>
. An fsx with a more detailed debug output can be found here: FSharpPlusAndTypeInference.fsx.