<div dir="ltr">Hi all,<div><br></div><div>One popular use of extensions is to take the definition of a type (e.g. MyBigClass) and to split it up over a number of files, grouping related methods together for increased code comprehensibility. However, access control makes doing so more difficult: members that are implementation details and declared as &#39;private&#39; can&#39;t be seen from other files.</div><div><br></div><div>I&#39;d like to suggest an access modifier: &quot;private(extension)&quot;. This follows in the spirit of the existing &quot;private(set)&quot; for properties. It would work in the following way:</div><div><br></div><div>- A member declared private(set) would be visible throughout the file within which it was declared, exactly as if it had been declared &quot;private&quot; today.</div><div>- A member declared private(set) would be visible in any file containing an extension to the member&#39;s type, throughout the entire file.</div><div>- This would only work for extensions to types declared within the same module; it would not be meant as a way to expose impl details to other modules or application code consuming the module.</div><div>- A property in T meant to be only gettable from other files, but settable from extensions to T in other files, would be declared &quot;private(set, extension)&quot;.</div><div><br></div><div>I think this is a reasonably elegant, small-surface-area solution to a common problem, but I can see some potential objections:</div><div><br></div><div>- It adds some complexity to the access control subsystem. Maybe that subsystem is complex enough as is.</div><div>- It might leak implementation details of a type T to code belonging to another type or global function, residing within the same file as an extension to T.</div><div>- Maybe there might be more elegant ways to improve or extend the access control subsystem.</div><div><br></div><div>Any thoughts?</div><div><br></div><div>Best,</div><div>Austin</div></div>