[swift-evolution] Make the type-casting operator accept expressions on its right side

Oscar Swanros oscar at swanros.com
Thu Jan 12 16:50:30 CST 2017


Hello everyone. This is my first contribution to Swift Evolution. In summary: It would be nice if the type casting operator accepted expressions on its right side.


So, basically, the type casting operator only accepts types and can't process expressions on its right side.

Having a class A, and a subclass of A, B:

class A {}
class B: A {}

And a function that returns the passed type:

func type<T: A>(t: T.Type) -> T.Type {
   return t
}

The following scenario works:

let b = B()
let a = (b as A)

However the following scenario doesn't:

let b = B()
let a = (b as type(A))




Having the “as” accept expressions on its right side would be really useful and could enable some truly great generic algorithm implementations.




Looking forward to what you guys think about this.

— Oscar Swanros | @swanros

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170112/a97b7bd8/attachment.html>


More information about the swift-evolution mailing list