[Issue 20607] [shared] static constructor & co can be called as regular function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 8 18:38:10 UTC 2020


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

--- Comment #6 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
(In reply to Mathias LANG from comment #5)
> > I don't see how. @system is designed to allow breaking the type system. @trusted code is not allowed to do so.
> 
> The compiler doesn't let you change `immutable` values in `@system`
> functions.

It does with a cast. It doesn't seem to me that calling a compiler-generated
function with an internal name is too different from that.

> > How is accessing identifiers by internal names accidental?
> 
> *Exposing* them was accidental.

What makes you say this?

> You can access them at runtime with module
> info. It would be good to have a way to access them at compile-time too, and
> I'm fine with this being a blocker to solve this issue. E.g. adding
> `__traits({ctors, dtor}, SYM)`.

It really seems unwarranted to me.

If they are callable in @safe, then that is a bug and I agree that it should be
fixed.

If the introspection says that the constructors are naught but regular
functions, then it's lying and that ought to be fixed. (Though, technically you
could have already inferred that from the name.)

But, if the code is calling it like a function (a valid operation for other
things in D, like function pointers / delegates / functors), that's surely
intentional. It seems really far-fetched that this could be something
accidental and we have to break things in order to "protect" users from it.

Another improvement could be to implicitly declare the constructors as private.
Currently, access modifiers apply to static constructors "predictably": public
constructors are "callable" from other modules, but private ones aren't.

--


More information about the Digitalmars-d-bugs mailing list