[swift-evolution] [swift-evolution-announce] [Review] SE-0096: Converting dynamicType from a property to an operator

Erica Sadun erica at ericasadun.com
Wed May 25 13:42:32 CDT 2016


> On May 25, 2016, at 12:26 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> I don't understand why the proposal says we can't implement this in the
> library today.  
> 
>  $ swift
>  Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.30). Type :help for assistance.
>    1> func dynamicType_<T>(_ x: T) -> T.Type { return x.dynamicType }
>    2> dynamicType_(42)
>  $R0: Int.Type = Int
>    3> class B {}
>    4. class C : B {}
>    5. dynamicType_(C() as B)
>  $R1: B.Type = __lldb_expr_5.C
>    6>
> 
> IMO exposing it as a special language feature is a mistake unless
> there's something wrong with the implementation above.  There are many
> ways we can implement the body of the generic function and still remove
> the .dynamicType property from the language's user model.


I'm going to defer to Joe Groff to respond specifically to this. I believe the
issue was that the type signature could not be described in today's Swift
but would be possible in future Swift, as the current type system wouldn't
work for protocol metatypes.

-- E



More information about the swift-evolution mailing list