6164 – [CTFE] Local arrays in a recursive local function behave funny

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6164 - [CTFE] Local arrays in a recursive local function behave funny
Summary: [CTFE] Local arrays in a recursive local function behave funny
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2011年06月16日 12:40 UTC by timon.gehr
Modified: 2011年06月23日 00:35 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011年06月16日 12:40:49 UTC
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.
Comment 1 kennytm 2011年06月16日 13:07:12 UTC
A workaround is to make ctfe2 a 'static function'.
Comment 2 Don 2011年06月23日 00:35:50 UTC
https://github.com/D-Programming-Language/dmd/commit/1ebe10d6796db6acf62b456d6f908391ec4daad5
(subsequently reverted, and then recommitted).


AltStyle によって変換されたページ (->オリジナル) /