on Wed Jun 29 2016, David Sweeris <davesweeris-AT-mac.com> wrote:

> (While I was typing this up, I realized that the exact usage you’re
> worried about, “MemoryLayout(Int.self).size” won’t compile, since
> `MemoryLayout` currently doesn’t have instance properties. If you’re
> worried about someone incorrectly typing out
> “MemoryLayout(Int.self).dynamicType.size”, though…)
>
> I made a rather critical typo in my earlier reply. It should’ve been
> “init(_: T.Type)”, instead of “init(_: T.self)”, which is to say this:
> extension MemoryLayout { // assuming `MemoryLayout<T>` is already defined as 
> proposed
>     public init(_ : T.Type) {} // makes it so that `MemoryLayout(T.self)` 
> still has the correct type for `T`
> }
>
> Here are the results of some quick playgrounding in the WWDC Xcode 8 beta:
> // without `init(_ : T.Type)` defined
> MemoryLayout<Int8>.size                       // 1, correct
> MemoryLayout(Int8.self).dynamicType.size      // 8, almost certainly wrong
> //MemoryLayout(Int8).dynamicType.size           // error
> MemoryLayout(0 as Int8).dynamicType.size      // 1, correct
> MemoryLayout<Int8.Type>.size                  // 8, correct
> MemoryLayout(Int8.Type.self).dynamicType.size // 8, correct, but is oddly 
> worded
> //MemoryLayout(Int8.Type).dynamicType.size      // error
>
> // with `init(_ : T.Type)` defined
> MemoryLayout<Int8>.size                       // 1, correct
> MemoryLayout(Int8.self).dynamicType.size      // 1, almost certainly correct
> MemoryLayout(Int8).dynamicType.size           // 1, almost certainly correct
> MemoryLayout(0 as Int8).dynamicType.size      // 1, correct
> MemoryLayout<Int8.Type>.size                  // 8, correct
> MemoryLayout(Int8.Type.self).dynamicType.size // 8, correct, but is oddly 
> worded
> MemoryLayout(Int8.Type).dynamicType.size      // 8, correct
>
> The only value that changes (aside from the errors) is the one “typo” that 
> you were worried about.
>
> Do this change your mind? 

No; it's too tricky. In your design MemoryLayout(x) now has two
different meanings depending on the type of x.

-- 
Dave
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to