Swift looses generic type information when casting [Any] to more specific type with as? operator

Originator:ilyapuchka
Number:rdar://23532339 Date Originated:13.10.15
Status:Open Resolved:
Product:Swift Product Version:2.1
Classification:Developer Tools Reproducible:
 
If I have instances of some generic type stored in array of Any and try to upcast this array to more specific type using as? operator and iterate it, it will cause crash at runtime on access to array item, but only on _second_ iteration of loop.

If instead I iterate array as array of Any and upcast each individual item inside loop body it works as expected.

Bug is demonstrated in this gist https://gist.github.com/ilyapuchka/28aee3ac5af4133ec93d
and in attached playground

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!