www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6164] New: [CTFE] Local arrays in a recursive local function behave funny

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

           Summary: [CTFE] Local arrays in a recursive local function
                    behave funny
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



This is tt.d:

import std.stdio;

string ctfe(){
    int[] ctfe2(int n){
        int[] r=[];
        if(n!=0) r~=[1]~ctfe2(n-1);
        return r;
    }
    return ctfe2(2).length == 2 ?
     "hello from runtime!" : "hello from compile time!";
}

void main(){
    pragma(msg,ctfe());
    writeln(ctfe());
}

$ dmd -run tt;
hello from compile time!
hello from runtime!
$

The ctfe'd result is generally longer than the correct one.
The example works as expected if ctfe2 is moved outside ctfe.

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


kennytm gmail.com changed:

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



A workaround is to make ctfe2 a 'static function'.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



https://github.com/D-Programming-Language/dmd/commit/1ebe10d6796db6acf62b456d6f908391ec4daad5

(subsequently reverted, and then recommitted).

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