Bug 12096 – Allow "body" to be used as an identifier
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-07T01:49:00Z
Last change time
2014-04-27T11:30:19Z
Assigned to
nobody
Creator
schuetzm
Comments
Comment #0 by schuetzm — 2014-02-07T01:49:29Z
copying from PR:
https://github.com/D-Programming-Language/dmd/pull/3227
Just recently a user wanted to use `body` as a member in his HTML document class:
http://forum.dlang.org/thread/[email protected]
I believe I've seen similar discussions several times in the forums.
Someone suggested to only treat `body` as a keyword where it makes sense. I tried implementing that, and, while not exactly beautiful, it turned out to be surprisingly non-invasive. It's not a keyword at all anymore, but a special identifier.
This same technique is also used for e.g. `scope(success)` among others, and could potentially be applied to other keywords too, but I guess `body` is the one with the greatest potential of conflict, because there is no nice alternative word (apart from capitalization and appending underscores etc.), and it's not a keyword in C/C++, so is freely used in some libraries.
See also this enhancement request, which proposes a different solution to the same problem:
http://d.puremagic.com/issues/show_bug.cgi?id=5775
Comment #1 by bearophile_hugs — 2014-02-07T09:57:21Z
Andrej Mitrovic suggests to improve the error messages instead:
void main()
{
int body;
}
test.d(5): Error: Cannot use keyword 'body' as a symbol name. Try to use `body_` instead.
It seems an acceptable solution.
Comment #2 by bugzilla — 2014-02-12T14:44:20Z
In hindsight, the choice of 'body' for the keyword is unfortunate. But fixing it would cause even worse problems, so I think we're stuck with it.
Comment #3 by andrej.mitrovich — 2014-04-27T11:30:19Z