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


--- Comment #0 from monkeyworks12 hotmail.com 2013-12-11 19:06:48 PST ---
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


--- Comment #1 from yebblies <yebblies gmail.com> 2013-12-12 22:51:16 EST ---
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



--- Comment #2 from monkeyworks12 hotmail.com 2013-12-12 09:10:54 PST ---
(In reply to comment #1)
 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


--- Comment #3 from yebblies <yebblies gmail.com> 2013-12-13 11:42:44 EST ---
(In reply to comment #2)
 
 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


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-12-12 17:26:22 PST ---
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



--- Comment #5 from github-bugzilla puremagic.com 2013-12-12 20:27:43 PST ---
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
Merge pull request #2956 from 9rnsr/fix11727

[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



--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2013-12-12 20:31:15 PST ---
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