[swift-evolution] Pitch: Limit typealias extensions to the typealias

Dave Abrahams dabrahams at apple.com
Sun Jun 11 18:00:10 CDT 2017

on Fri Jun 09 2017, Matthew Johnson <swift-evolution at swift.org> wrote:

>> On Jun 9, 2017, at 12:09 PM, Xiaodi Wu via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> On Fri, Jun 9, 2017 at 12:44 Robert Bennett via swift-evolution
>> <swift-evolution at swift.org
>> <mailto:swift-evolution at swift.org>>
>> wrote:
>> Somewhat related to this, shouldn’t it be possible to sub-struct a
>> struct as long as you only add functions and computed properties
>> (i.e., no stored properties)? Traditionally structs cannot be
>> subtyped because their size must be known at compile time. I don’t
>> know the implementation details of where functions and computed
>> properties live, but something tells me they belong to the type and
>> not the object (although I’ve never really made the effort to sit
>> down and fully understand Swift’s type model), in which case adding
>> them to a struct’s definition would not change the size of the
>> object on the stack. Thus it should be possible to make custom
>> substructs of String that add additional functionality but no new
>> stored properties. Thoughts?
>> Value subtyping is a large subject and, IIUC, newtype would be a
>> subset of that topic. Unlikely to be in scope for Swift 5, though,
>> but that’s up to the core team.
> I see newtype as being more related to forwarding than subtyping.
> Usually you want to hide significant parts of the interface to the
> wrapped type.

Yes, and whether you want an implicit conversion relationship between
the newtype and the old is an orthogonal issue.


More information about the swift-evolution mailing list