Thread overview
[Issue 7719] New: enum forward reference error when enum is in braces
Mar 16, 2012
Andrej Mitrovic
Mar 17, 2012
Andrej Mitrovic
Oct 04, 2012
Andrej Mitrovic
Apr 01, 2013
Kenji Hara
Apr 03, 2013
Walter Bright
March 16, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7719

           Summary: enum forward reference error when enum is in braces
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-03-16 16:06:18 PDT ---
enum foo = bar;
enum {
    bar = 1
}
void main() { }

test.d(3): Error: undefined identifier bar

Yet this works ok:
enum foo = bar;
enum bar = 1;
void main() { }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7719



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-03-16 17:13:03 PDT ---
There are more issues with these enums inside of brackets. Right now I'm having the weirdest errors where referencing these enums doesn't work from a class defined below it:

enum
{
    wxUSER_ATTENTION_INFO = 1,
    wxUSER_ATTENTION_ERROR = 2,
}

If they're each defined separately:
enum wxUSER_ATTENTION_INFO = 1;
enum wxUSER_ATTENTION_ERROR = 2;

then it works. I don't have a minimal test-case for this now (working on it), but there's obviously some issues with the implementation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 04, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7719



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-04 08:25:05 PDT ---
I've found some lead:

in enum.c:

void EnumDeclaration::semantic0(Scope *sc)
{
    /* This function is a hack to get around a significant problem.
     * The members of anonymous enums, like:
     *  enum { A, B, C }
     * don't get installed into the symbol table until after they are
     * semantically analyzed, yet they're supposed to go into the enclosing
     * scope's table. Hence, when forward referenced, they come out as
     * 'undefined'. The real fix is to add them in at addSymbol() time.
     * But to get code to compile, we'll just do this quick hack at the moment
     * to compile it if it doesn't depend on anything else.
     */

    if (isdone || !scope)
        return;
    if (!isAnonymous() || memtype)
        return;
    for (size_t i = 0; i < members->dim; i++)
    {
        EnumMember *em = (*members)[i]->isEnumMember();
        if (em && (em->type || em->value))
            return;
    }

    // Can do it
    semantic(sc);
}

If I remove the for loop and let semantic do its work the OP code compiles. But I don't know the extent of this hack that's in place now, whether it's still necessary or not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7719


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-01 05:44:52 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1821

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7719



--- Comment #4 from github-bugzilla@puremagic.com 2013-04-03 10:28:49 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b7b239cf8d37a9bdcf720c6e359d5937eeaa7ee7 fix Issue 7719 - enum forward reference error when enum is in braces

https://github.com/D-Programming-Language/dmd/commit/33ca607a13d799a7fdc96d3be9f10048246863a3 Merge pull request #1821 from 9rnsr/fix9845

Issue 7719,9845,9846 - fix anonymous enum and forward reference problems

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=7719


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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