[Issue 16394] TypeInfo.init() for static arrays returns single element instead of whole array

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Aug 16 05:49:09 PDT 2016


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

--- Comment #11 from ag0aep6g at gmail.com ---
Alright, these are arguments for changing the documentation instead of the
implementation:

1) Changing the behavior would break existing code.
2) It's hard or impossible to fix in a satisfactory way. In particular: binary
bloat.

If I'm missing or misrepresenting anything, please yell at me.

Re 1: I agree that it may break existing code, which isn't good. I don't assign
a lot of value to this, though. I.e., yes it's a bit bad, but in my opinion the
bad doesn't outweigh the good we would get from having the function behave as
documented. The documented behavior is far more sensible (to the user) than the
actual behavior. The code that would get broken by a fix is likely workaround
code for the inconsistency.

Re 2: I don't know how much bloat a fix would add, but consider that we can
embed a static array in a struct, and `initializer` works as documented then.
So that case has the bloat and everything seems to be just fine.

In code:
----
struct S { char[3] a; }
void main()
{
    assert(typeid(S).initializer == "\xFF\xFF\xFF"); /* passes */
    assert(typeid(char[3]).initializer == "\xFF\xFF\xFF"); /* fails */
}
----

--


More information about the Digitalmars-d-bugs mailing list