[swift-evolution] Proposal - Allow properties in Extensions

Jordan Rose jordan_rose at apple.com
Tue Dec 22 21:40:42 CST 2015


> On Dec 18, 2015, at 20:11 , Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Dec 18, 2015, at 4:11 PM, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> One potentially large downside is you can no longer look at a type declaration and find out how large it is. For example, I could define
>>> 
>>> struct Foo {
>>>  var x: Int
>>> }
>>> 
>>> and it looks like a tiny struct, but I could then add an extension in a separate file that bloats that out to some ridiculously massive struct, and that wouldn't be obvious from looking at it.
>> 
>> I think any storage-in-extensions proposal ought to be a special feature of classes; I would not support the ability to add stored properties to structs in extensions, even from within the module.
> 
> I agree.

I don't see why any reasons that apply to classes wouldn't apply to structs: code organization, making the property private, etc. But maybe it should be called out explicitly with "@partial" or similar for structs.

Jordan


More information about the swift-evolution mailing list