www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12096] New: Allow "body" to be used as an identifier

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12096

           Summary: Allow "body" to be used as an identifier
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: schuetzm gmx.net


--- Comment #0 from Marc Schütz <schuetzm gmx.net> 2014-02-07 01:49:29 PST ---
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/vbfrootcxaecjgciwlvb forum.dlang.org
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

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12096


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2014-02-07 09:57:21 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 07 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12096


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2014-02-12
14:44:20 PST ---
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.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 12 2014