6934 – [CTFE] can't use $ in a slice of an array passed by ref

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6934 - [CTFE] can't use $ in a slice of an array passed by ref
Summary: [CTFE] can't use $ in a slice of an array passed by ref
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
: 7109 (view as issue list)
Depends on:
Blocks:
Reported: 2011年11月11日 19:41 UTC by bearophile_hugs
Modified: 2015年06月09日 05:11 UTC (History)
3 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 bearophile_hugs 2011年11月11日 19:41:18 UTC
It seems transversal() can't run at compile-time:
import std.range: transversal;
int foo() {
 auto M = [[1,2], [3,4]];
 foreach (x; transversal(M, 0)) {}
 return 0;
}
enum _ = foo();
void main() {}
DMD 2.057head gives:
...\dmd2\src\phobos\std\array.d(328): Error: Cannot determine length of Transversal([[1,2],[3,4]],0u)._input at compile time
...\dmd2\src\phobos\std\range.d(4648): called from here: popFront(this._input)
test.d(4): called from here: __r1.popFront()
test.d(7): called from here: foo()
Comment 1 Don 2011年11月19日 00:03:47 UTC
Reduced test case:
------
struct Struct6934 {
 int[] x = [1,2];
}
void bar6934(ref int[] p) {
 p = p[1..$];
}
int bug6934() {
 Struct6934 q;
 bar6934(q.x);
 return 1;
}
static assert(bug6934());
Comment 2 Don 2011年11月19日 12:24:51 UTC
In fact passing arrays by reference is broken in non-trivial cases.
Changing the test case to include an index or slice assignment reveals wrong-code problems:
void bar6934(ref int[] p) {
 p[0] = 12;
 assert(p[0] == 12); // fails!!!
 p[0..1] = 17;
 assert(p[0] == 17); // fails!!! 
 p = p[1..$];
}
This applies to any complicated passing of an array by ref (any dotvar or index expression, or combination thereof).
It applies to array index assignment, and slice assignment.
Comment 4 Don 2011年12月14日 23:04:34 UTC
*** Issue 7109 has been marked as a duplicate of this issue. ***


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