www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4274] New: Better array of inner structs error message

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

           Summary: Better array of inner structs error message
           Product: D
           Version: future
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-06-04 18:20:50 PDT ---
This wrong D2 program:

void main() {
    struct Foo {
        void bar() {}
    }
    auto foos = new Foo[1]; // line 5
}


At compile time dmd v2.046 prints:
temp.d(5): Error: cannot have array of inner structs Foo

But for D newbies coming from C or C++ can find that error message cryptic.
Using a static struct solves this problem. So a possible error message can be:

temp.d(5): Error: cannot have array of inner structs Foo, you can use a 'static
struct' instead.

This improved error message is not perfect, but it seems better.

(I don't understand why D error messages don't have the ending full stop.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274


nfxjfg gmail.com changed:

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


--- Comment #1 from nfxjfg gmail.com 2010-06-05 04:33:03 PDT ---
I don't understand why arrays of inner structs shouldn't be possible.
Is this just another seemingly random restriction with no real foundation of
the dmd compiler?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274



--- Comment #2 from bearophile_hugs eml.cc 2010-06-05 04:50:08 PDT ---
Structs defined inside functions keep a hidden pointer field to the function
they are into. If you return the array of nonstatic structs, the scope stops
existing and this pointer points to garbage. To avoid this you need 'struct
closures', but I prefer to avoid them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274



--- Comment #3 from nfxjfg gmail.com 2010-06-05 05:04:20 PDT ---
So what? You _can_ have an array of closures.
Why not an array of nested structs?
The compiler should obviously allocate all variables referenced by the struct
on the heap, just like it is done with closures.
Otherwise, it's an half-implemented garbage feature that should be removed
before it causes any more harm.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274



--- Comment #4 from nfxjfg gmail.com 2010-06-05 05:10:24 PDT ---
I just tested it, and it seems for nested structs, the compiler correctly
allocates upvalues on the heap. The error message you're receiving doesn't make
any sense. At least the reason for it must different.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274


nfxjfg gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal


--- Comment #5 from nfxjfg gmail.com 2010-06-08 04:28:26 PDT ---
Turning this into a "real" bug; maybe I'm wrong though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 08 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4274


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
         Resolution|                            |FIXED
         OS/Version|Windows                     |All


--- Comment #6 from yebblies <yebblies gmail.com> 2011-07-01 21:52:59 EST ---
Arrays of nested structs are now allowed (dmd 1.068 & dmd 2.053)

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