www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11727] New: [ICE] Returning an enum with no value from a function fails

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

           Summary: [ICE] Returning an enum with no value from a function
                    fails
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monkeyworks12 hotmail.com



auto returnEnum()
{
        //Fails with "dmd: mtype.c:7620: virtual Type* TypeEnum::nextOf():
Assertion `sym->scope' failed."
    //enum n;
        enum n = 0; //Ok
    return n;
}

void main()
{
    assert(returnEnum() == 0);
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 11 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



I get:

DMD v2.065 DEBUG
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
base type
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
base type
testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
base type
testx.d(11): Error: incompatible types for ((returnEnum()) == (0)): 'n' and
'int'

With the latest compiler.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727





 I get:
 
 DMD v2.065 DEBUG
 testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
 base type
 testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
 base type
 testx.d(4): Error: enum testx.returnEnum.n is forward referenced looking for
 base type
 testx.d(11): Error: incompatible types for ((returnEnum()) == (0)): 'n' and
 'int'
 
 With the latest compiler.
My mistake, I tested this on Dpaste and must not have set it to Git HEAD. Still, should this be changed to rejects-valid? It seems to me that n should default to type int and value 0. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Summary|[ICE] Returning an enum     |Repeated error message with
                   |with no value from a        |using forward referenced
                   |function fails              |enum as variable
           Severity|critical                    |normal




 
 My mistake, I tested this on Dpaste and must not have set it to Git HEAD.
 Still, should this be changed to rejects-valid? It seems to me that n should
 default to type int and value 0.
enum n; isn't an enum variable with no value, it's a forward declaration of an enum type 'n'. (like "struct s;") Enum variables must always have an initializer. The error message obviously could be improved. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
           Platform|Other                       |All
         OS/Version|Other                       |All



https://github.com/D-Programming-Language/dmd/pull/2956

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/65d3e9019f1f06a436ff3f8d922d63df7bc7479b
fix Issue 11727 - Repeated error message with using forward referenced enum as
variable

https://github.com/D-Programming-Language/dmd/commit/a5ae10d83cef074c93e25c174b3d80536eae700a


[diag] Issue 11727 - Repeated error message with using forward referenced enum
as variable

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11727




Now the OP code:

auto returnEnum()
{
    enum n;
    return n;  // Line 4
}
void main()
{
    assert(returnEnum() == 0);
}

Prints:

test.d(4): Error: type n has no value

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