Bug 9547 – typeof() which requires .init must be properly documented
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-19T20:46:00Z
Last change time
2013-09-17T16:01:49Z
Keywords
spec
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-02-19T20:46:48Z
import std.range;
void getArray(T)()
{
alias ElementType!T ElemType1; // OK
alias typeof(T[0]) ElemType2; // NG
}
void main()
{
getArray!(string[])();
}
This worked in 2.061, and broke LuaD in 2.062. The workaround (or rather the new valid code) is:
alias typeof(T.init[0]) ElemType;
However this change *must* be clearly documented in the changelog, and the requirement should be part of the documentation somewhere.
Comment #1 by andrej.mitrovich — 2013-02-19T20:50:43Z
(In reply to comment #0)
> However this change *must* be clearly documented in the changelog, and the
> requirement should be part of the documentation somewhere.
In addition to that we should change the error message, and perhaps even consider warning the user of a change. E.g. the current error:
> Error: argument string[][0u] to typeof is not an expression
It could be:
Error: Cannot index into a type 'T[0u]', perhaps you meant 'T.init[0]' ?
Comment #2 by k.hara.pg — 2013-02-19T21:02:53Z
(In reply to comment #0)
> This worked in 2.061, and broke LuaD in 2.062. The workaround (or rather the
> new valid code) is:
>
> alias typeof(T.init[0]) ElemType;
This is bug fix for issue 6408. `T[0]` should be always analyzed as "zero length static array of T", but it was *accidentally* treated as T.init[0].
> However this change *must* be clearly documented in the changelog, and the
> requirement should be part of the documentation somewhere.
I can agree that some of proper bug fixes require clear explanation for better migration. We need to pay attention for them in beta phase, and document them.
Comment #3 by andrej.mitrovich — 2013-02-19T21:09:52Z
(In reply to comment #2)
> This is bug fix for issue 6408. `T[0]` should be always analyzed as "zero
> length static array of T", but it was *accidentally* treated as T.init[0].
Yeah I had a vague memory of this being fixed recently. It's a good change.
> I can agree that some of proper bug fixes require clear explanation for better
> migration. We need to pay attention for them in beta phase, and document them.
For the upcoming 2.063 release I suggest we keep a special text file (e.g. a local "changes" file in DMD git) where each language change is documented every time such a pull request is merged. This will make sure we never forget to document a language change (it is much harder to do this at the end when there are 150+ bugs fixed).
Comment #4 by andrej.mitrovich — 2013-09-17T16:01:49Z
Fixed in 2.063, we've had a good changelog for it.