www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Regression] Cannot assign scalar variable to char[], byte[] or ubyte[]

Using DMD 0.100, Windows 98SE.

One of my very first D programs has stopped working.  In particular, 
assignment of a scalar variable to a char[] slice refuses to work, 
instead giving me garbage or an AV for some reason I can't imagine.

----------
import std.stdio;

void main() {
	char[] qwert = new char[4];
	char yuiop = 'c';

	qwert[0..4] = 'a';
	show(qwert);

	qwert[] = 'b';
	show(qwert);

	qwert[0..4] = yuiop;
	show(qwert);

	qwert[] = yuiop;
	show(qwert);
}


void show(char[] s) {
	foreach (int i, char c; s) {
		writefln("qwert[%d] == %d", i, cast(int) c);
	}
}
----------

Actual output:
qwert[0] == 97
qwert[1] == 97
qwert[2] == 97
qwert[3] == 97
qwert[0] == 98
qwert[1] == 98
qwert[2] == 98
qwert[3] == 98
qwert[0] == 249
qwert[1] == 35
qwert[2] == 71
qwert[3] == 0
Error: Access Violation

Expected output:
qwert[0] == 97
qwert[1] == 97
qwert[2] == 97
qwert[3] == 97
qwert[0] == 98
qwert[1] == 98
qwert[2] == 98
qwert[3] == 98
qwert[0] == 99
qwert[1] == 99
qwert[2] == 99
qwert[3] == 99
qwert[0] == 99
qwert[1] == 99
qwert[2] == 99
qwert[3] == 99

The garbage changes when I change my code a bit.  If I take out lines 
7-11, I get:

qwert[0] == 32
qwert[1] == 0
qwert[2] == 0
qwert[3] == 0
Error: Access Violation

As you see, it works on literals, but not variables.  The bug is the 
same if I use ints as the rvalues, or assign to a byte[] or ubyte[] 
instead of a char[].  But it works OK with arrays of the other integral 
types.

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
Sep 15 2004