www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12528] New: foreach with inout ref argument cannot be interpreted at compile time

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

           Summary: foreach with inout ref argument cannot be interpreted
                    at compile time
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: CTFE
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code dawg.eu


--- Comment #0 from Martin Nowak <code dawg.eu> 2014-04-06 08:33:39 PDT ---
cat > bug.d << CODE
inout(T)[] dup(T)(inout(T)[] a)
{
    inout(T)[] res;
    foreach (ref e; a)
        res ~= e;
    return res;
}

enum works = dup([0]);
enum trigger = dup([0, 1]);
CODE

dmd -c bug.d
----
bug.d(5): Error: Cannot interpret res ~= e at compile time
bug.d(10):        called from here: dup([0, 1])
----

Probably some issue when reassigning the foreach argument because it's only
triggered when the array has more than one element.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12528



--- Comment #1 from Martin Nowak <code dawg.eu> 2014-04-06 09:25:29 PDT ---
workaround:

foreach (ref e; a)
    res ~= [e];

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12528


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2014-04-06 23:53:52 PDT ---
https://github.com/D-Programming-Language/dmd/pull/3430

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 06 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12528



--- Comment #3 from github-bugzilla puremagic.com 2014-04-07 02:58:40 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b3d3eeb2223fa521b8653ed0a4ef3f749b2b11b7
fix Issue 12528 - [CTFE] cannot append elements from one inout array to another
inout array

https://github.com/D-Programming-Language/dmd/commit/b3d2ca068a976a6f69447502edb3779d97897642
Merge pull request #3430 from 9rnsr/fix12528

Issue 12528 - [CTFE] cannot append elements from one inout array to another
inout array

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12528


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: -------
Apr 07 2014