www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10276] New: Compiler pointlessly makes a struct nested even if it doesn't need to be

http://d.puremagic.com/issues/show_bug.cgi?id=10276

           Summary: Compiler pointlessly makes a struct nested even if it
                    doesn't need to be
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



09:40:41 PDT ---
-----
import std.traits;

unittest
{
    /* static */ struct S1
    {
        int x;
    }

    /* static */ struct S2
    {
        this(int) { }
        int x;
    }


    static assert(!isNested!S1);
    static assert(!isNested!S2);  // fails
}

void main()
{
}
-----

There is absolutely no need to make a struct nested *unless* it needs the
context pointer. The compiler seems to make it a nested type as soon as it has
any function or ctor implemented. This seems like arbitrary behavior.

This is a problem with structs defined within unittests, because they end up
breaking template code in weird ways (for example nested types can't be used
with T.init).

Using static explicitly is of course the workaround, but it should never be a
requirement. The compiler should prefer making a struct static *unless* it has
to do otherwise.

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