Thread overview
[Issue 6937] New: new with struct doesn't allow field assignment
Nov 12, 2011
dawg@dawgfoto.de
Dec 07, 2012
Kenji Hara
Dec 07, 2012
Kenji Hara
November 12, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6937

           Summary: new with struct doesn't allow field assignment
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dawg@dawgfoto.de


--- Comment #0 from dawg@dawgfoto.de 2011-11-12 08:44:16 PST ---
struct
{
  int a;
}

auto s1 = S(2); // works
auto s2 = new S(2); // doesn't work

----------

New with struct strictly requires a defined constructor while
it should have the same construction rules as a normal struct literal.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6937



--- Comment #1 from github-bugzilla@puremagic.com 2012-12-06 18:38:18 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4a22ca0053252454c5cddab2c5754b8a2f500544 fix Issue 6937 - new with struct doesn't allow field assignment

https://github.com/D-Programming-Language/dmd/commit/ee695eb92086cb73f62e7e01f019171776308435 Merge pull request #1353 from 9rnsr/fix6937

Issue 6937 - new with struct doesn't allow field assignment

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6937


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #2 from bearophile_hugs@eml.cc 2012-12-06 19:10:36 PST ---
Despite this looks like a silent little change, this is a significant improvement in D, and it's one of the best improvements for DMD 2.061. This removes some useless code from my D2 code base.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6937



--- Comment #3 from bearophile_hugs@eml.cc 2012-12-06 19:37:53 PST ---
(In reply to comment #2)
> Despite this looks like a silent little change, this is a significant improvement in D, and it's one of the best improvements for DMD 2.061. This removes some useless code from my D2 code base.

This is not yet allowed to remove some more boilerplate code (the "new"):


struct Node(T) {
    T data;
    Node* left, right;
}
void main() {
    alias N = Node!int;
    auto t1 = new N(1, new N(2, new N(3))); // OK
    alias M = Node!int.__ctor; // Not OK
    auto t2 = M(1, M(2, M(3)));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6937



--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2012-12-06 19:46:54 PST ---
(In reply to comment #3)
> This is not yet allowed to remove some more boilerplate code (the "new"):
> 
> 
> struct Node(T) {
>     T data;
>     Node* left, right;
> }
> void main() {
>     alias N = Node!int;
>     auto t1 = new N(1, new N(2, new N(3))); // OK
>     alias M = Node!int.__ctor; // Not OK
>     auto t2 = M(1, M(2, M(3)));
> }

This is completely unrelated to this issue.
Ideally __ctor should not appear in user code, and language specification would
never support it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6937


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

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


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