Horusiath / fsharp.core.extensions

A set of utilities, that you always wanted to have in F#.
126 stars 5 forks source link

Textual error message when printing Vec #6

Open fnzr opened 3 years ago

fnzr commented 3 years ago

When using printfn to print a member of Vec, the message "Error: Index was outside the bounds of the array" is shown. There's no actual error occuring. Example:

let main argv =
    let vec1 = Vec.ofSeq ['a'; 'b'; 'c']
    printfn "%A" vec1 //error
    Vec.iter (printfn "%A") vec1 //ok
    let vec2, _ = vec1.Pop ()
    printfn "%A" vec2 //error
    printfn "%A" [vec2.[0];vec2.[1]] //ok
    0

Output:

Error: Index was outside the bounds of the array.
'a'
'b'
'c'
Error: Index was outside the bounds of the array.
['a'; 'b']

Expected output (or similar):

['a'; 'b'; 'c']
'a'
'b'
'c'
['a'; 'b']
['a'; 'b']

I cloned the most recent version, commit 2983d0293e0ea366d833dc052efdc078cd268272

Horusiath commented 3 years ago

Thanks @fnzr - I'll take a look at it. In general %A flag means, that you're using .NET reflection to introspect an object and take its contents. It may be problematic to fix it. If you'd use %O flag instead, you'd use a native Vec.ToString method, which prints the contents correctly.

fnzr commented 3 years ago

Oh, I see. This solution is good enough for me, feel free to close this issue. Thanks!