Skip to content

Commit 0a31cd3

Browse files
kbattocchiKevinRansom
authored andcommitted
Make Seq.cast's non-generic and generic IEnumerable implementations equivalent
1 parent 12ee48c commit 0a31cd3

File tree

2 files changed

+16
-4
lines changed
  • src/fsharp
    • FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections
    • FSharp.Core

2 files changed

+16
-4
lines changed

src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,19 @@ type SeqModule() =
260260
let expectedNullSeq = seq [null;null]
261261

262262
VerifySeqsEqual expectedNullSeq NullSeq
263-
263+
264+
CheckThrowsExn<System.InvalidCastException>(fun () ->
265+
let strings =
266+
integerArray
267+
|> Seq.cast<string>
268+
for o in strings do ())
269+
270+
CheckThrowsExn<System.InvalidCastException>(fun () ->
271+
let strings =
272+
integerArray
273+
|> Seq.cast<string>
274+
:> System.Collections.IEnumerable // without this upcast the for loop throws, so it should with this upcast too
275+
for o in strings do ())
264276

265277
()
266278

src/fsharp/FSharp.Core/seq.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ namespace Microsoft.FSharp.Collections
2525

2626
let cast (e : IEnumerator) : IEnumerator<'T> =
2727
{ new IEnumerator<'T> with
28-
member x.Current = unbox e.Current
28+
member x.Current = unbox<'T> e.Current
2929
interface IEnumerator with
30-
member x.Current = unbox e.Current
30+
member x.Current = unbox<'T> e.Current :> obj
3131
member x.MoveNext() = e.MoveNext()
32-
member x.Reset() = noReset();
32+
member x.Reset() = noReset()
3333
interface System.IDisposable with
3434
member x.Dispose() =
3535
match e with

0 commit comments

Comments
 (0)