D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4064 - [CTFE] array.reverse doesn't work
Summary: [CTFE] array.reverse doesn't work
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-04-05 05:32 UTC by bearophile_hugs
Modified: 2015-06-09 05:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-04-05 05:32:09 UTC
bool foo(int[] arr) {
    arr.reverse;
    return arr == [2, 1];
}
enum bool r = foo([1, 2]);
void main() {}


dmd 2.042 gives:

test.d(2): Error: cannot evaluate _adReverse(arr,4u) at compile time
test.d(5): Error: cannot evaluate foo([1,2]) at compile time
test.d(5): Error: cannot evaluate foo([1,2]) at compile time
Comment 1 Don 2010-04-10 21:52:53 UTC
Note that ANY call to the runtime cannot be be interpreted in CTFE (because source code is not available). This bug, like bug 4021, is an enhancement request.

The spec specifically says that .dup, .length, .keys, and .values are the only built-in properties which are supported in CTFE. To support these others, they would need to be (a) moved out of the runtime; or (b) special-cased in the interpreter. And case (b) is not going to happen.


In 2.043, this gives the error message:

crash.d(38): Error: _adReverse cannot be interpreted at compile time, because it
 has no available source code
crash.d(41): Error: cannot evaluate foo([1,2]) at compile time
crash.d(41): Error: cannot evaluate foo([1,2]) at compile time

which I think is slightly improved from before -- it at least explains that the missing source code is the reason why it cannot work.
Comment 2 bearophile_hugs 2010-04-11 04:31:42 UTC
Thank you for the comments. A third (c) possibility is to change the way CTFE is done, avoiding some duplication in the compiler.
Comment 3 Don 2011-11-02 17:43:02 UTC
Wontfix: Builtin .reverse and .sort are shameful and will hopefully be removed from the language soon. The standard library functions work in CTFE now.