Skip to content

Strange error in Seq.take on count exceeding length #9490

@nightroman

Description

@nightroman

Strange error in Seq.take on count exceeding length

Repro steps

Create 1.fsx:

[1..2]
|> Seq.take 3
|> printfn "%A"

printfn "done"

Invoke as:

fsi 1.fsx

Output:

Error: tried to take The input sequence has an insufficient number of elements. 2 past the end of the seq
done

Actual behavior

(1) The error message is formatted in a strange way.

(2) The message appears to be incorrect, we have 1 extra item, not 2.

(3) The error (exception?) does not stop the execution, see "done" printed.

Expected behavior

The expected behavior is similar to List.take and Array.take.
Most importantly, the exception should terminate the execution.

List.take version:

[1..2]
|> List.take 3
|> printfn "%A"

printfn "done"
System.InvalidOperationException: The input sequence has an insufficient number of elements.
The list was 1 element shorter than the index
   at ...
Stopped due to error

Also note the correct "1 element shorter".

Array.take version:

[|1..2|]
|> Array.take 3
|> printfn "%A"

printfn "done"
System.InvalidOperationException: The input sequence has an insufficient number of elements.
   at ...
Stopped due to error

Also note no information on the exceeding element count, unlike in Seq.take and List.take.

Ideally, all 3 Seq.take, List.take, and Array.take should have similar error messages.

Known workarounds

None.

Related information

  • Windows 10, x64
  • .NET Framework
  • Runners:
    • fsi.exe of Visual Studio 2019 (16.6.2)
    • similar tools built with FSharp.Compiler.Service (36.0.1) using FSharp.Core (4.7.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-LibraryIssues for FSharp.Core not covered elsewhereBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions