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

David Sweeris davesweeris at mac.com
Thu Jan 12 17:00:46 CST 2017


> On Jan 12, 2017, at 16:50, Oscar Swanros via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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.

+1 for the functionality, but I think it's part of the larger issue of "functions which can be evaluated at compile-time", which, IIRC, is presently considered out of scope (can't recall if that's just for phase 1 or Swift 4 altogether). I might be wrong, though. I'm sure someone who knows more than I do will be along shortly with a better answer.

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


More information about the swift-evolution mailing list