[svn r55] Foreach was always generating code as if the value variable was 'ref'

Other not-so-major improvements
This commit is contained in:
Tomas Lindquist Olsen
2007-10-22 17:25:44 +02:00
parent a9189bd3a9
commit 2c99df8deb
7 changed files with 100 additions and 43 deletions

24
test/foreach5.d Normal file
View File

@@ -0,0 +1,24 @@
module foreach5;
void main()
{
int[3] arr = [1,2,3];
foreach(v;arr) {
v++;
}
printf("%d\n", arr[0]);
assert(arr[0] == 1);
assert(arr[1] == 2);
assert(arr[2] == 3);
foreach(ref v;arr) {
v++;
}
printf("%d\n", arr[0]);
assert(arr[0] == 2);
assert(arr[1] == 3);
assert(arr[2] == 4);
}

15
test/foreach6.d Normal file
View File

@@ -0,0 +1,15 @@
module foreach6;
struct S
{
long l;
float f;
}
void main()
{
S[4] arr;
foreach(i,v;arr) {
v = S(i,i*2.5);
}
}