www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1253] New: DMD 0.175 introduced bug: array initializers as expressions are not allowed?

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

           Summary: DMD 0.175 introduced bug: array initializers as
                    expressions are not allowed?
           Product: D
           Version: 0.175
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: oskar.linde gmail.com


void main() {   
    struct T { int a; int b;}   
    const T[] arr = [{1,1},{2,2}];
    T[] arr2 = arr.dup;
    assert(arr2 == arr);
}

Gives:

test.d:3: Error: array initializers as expressions are not allowed
test.d:3: Error: array initializers as expressions are not allowed

Interestingly, commenting out the assert line makes the code compile.
changing const -> static also makes the code compile.

The bug is confirmed to exist on 0.175, 0.176, 0.178, 1.006, 1.007, 1.013 (gdc
0.23) and 1.014

On DMD 0.174 (and earlier), the code compiles ok.


-- 
Jun 01 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Severity|major                       |regression




-- 
Jun 01 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253






Added to DStress as
http://dstress.kuehne.cn/run/s/struct_initialization_11_A.d
http://dstress.kuehne.cn/run/s/struct_initialization_11_B.d
http://dstress.kuehne.cn/run/s/struct_initialization_11_C.d


-- 
Aug 25 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253






exists in 2.012, doesn't depend on asserts

struct A
{
  int a,b;
}

void f()
{
  A[2] rg=[{1,2},{1,2}];
}


-- 
May 11 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253






workaround :-/

struct A
{
        int a,b;
}

void f()
{
        A[2] rg=[A(1,2),A(3,4)];
}


-- 
May 11 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253






other initialization-related info
bug 2096, bug 2170, bug 2356, bug 2375


-- 
Sep 30 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Version|0.175                       |2.022
            Summary|DMD 0.175 introduced bug:   |array initializers as
                   |array initializers as       |expressions are not allowed
                   |expressions are not         |in const arrays
                   |allowed?                    |
           Severity|regression                  |normal





This works for me on D1.046. It was fixed somewhere between 1.020 and 1.041.

It also works on DMD2.031, if you change 'const' to 'enum' to preserve the
semantics.

Oddly, however, on DMD2.031 the code as-written still displays:

bug.d(173): Error: array initializers as expressions are not allowed

So this is now a D2-only bug, which is not a regression. It's never worked with
these semantics. Checked as far back as 2.022.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch





And here's a patch.
Cause: The initializer is used in declaration.c, VarDeclaration::semantic().
We see the lines:
------
            Expression *e = init->toExpression();
            if (!e)
            {
            init = init->semantic(sc, type);
            e = init->toExpression();
            if (!e)
------
The initializer is supposed to return NULL if the initializer semantic hasn't
been run yet. But the array initializer doesn't -- it prints an error, and
returns an ErrorExp instead! It never has a chance.

PATCH: init.c, last lines of ArrayInitializer::toExpression() (around line
473).

Lno:
    delete elements;
-   error(loc, "array initializers as expressions are not allowed");
-   return new ErrorExp();
+    return NULL;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 01 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1253


Walter Bright <bugzilla digitalmars.com> changed:

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



02:19:51 PDT ---
Fixed dmd 2.033

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