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

Dave Abrahams dabrahams at apple.com
Wed May 25 14:28:00 CDT 2016


on Wed May 25 2016, Joe Groff <jgroff-AT-apple.com> wrote:

>> On May 25, 2016, at 11:42 AM, Erica Sadun <erica at ericasadun.com> wrote:
>> 
>> 
>>> 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>
>
> Now try it with a protocol type, or Any:
>
> (swift) var x: Any = 1738
> // x : Any = 1738
> (swift) dynamicType_(x)
> // r0 : Any.Protocol = protocol<>
>
> `dynamicType` is really two operations: For normal concrete types, it
> produces concrete metatypes, and for existentials, it produces
> existential metatypes. There's no way to express the latter for an
> arbitrary unknown protocol type in the language today.

Can't we detect in the runtime library that we've got an existential and
do the right thing?

-- 
Dave


More information about the swift-evolution mailing list