Bug 21141 – No introspection access to a field's default value

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-10T01:23:55Z
Last change time
2024-12-13T19:10:45Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Moved to GitHub: dmd#19763 →

Comments

Comment #0 by andrei — 2020-08-10T01:23:55Z
Structs and classes should offer for introspection each field's default value. That should be available as a string that can be mixed in. For void initialization, the string would naturally be "void". A simpler alternative would be to just offer an array of immutable bytes that can be used to initialize the object. That is suboptimal because it does not skip void-initialized fields. This blocks https://github.com/dlang/druntime/pull/3174.
Comment #1 by destructionator — 2020-08-10T01:32:40Z
A string is going to hit trouble with module imports and such. It could possibly be a function though, and a void function represents the void initializer. (hopefully this would be a function the compiler knows it can always ctfe optimize away).
Comment #2 by bugzilla — 2020-08-10T21:53:16Z
The difficulty with a field-by-field initializer is being careful about where the holes go and overlapping fields.
Comment #3 by robert.schadek — 2024-12-13T19:10:45Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19763 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB