[Issue 20358] External initialization of private struct fields should be disallowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 6 10:24:34 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20358

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras at gmail.com

--- Comment #2 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Supporting Max's argument: test.d's author should have no knowledge of S's
private fields and their allowed values. A change in S's internals would lead
to breakage in unrelated modules.

The solution here would be to define the default constructor as private when a
struct has private members. Inside s.d this would allow the exact same usage as
now, while not giving other modules access to internals that arguably shouldn't
be available to them. Constructors would need to be defined explicitly to
initialize private fields when called from other modules.

I started out agreeing with RazvanN on this, but I think the above is the best
solution.

--


More information about the Digitalmars-d-bugs mailing list