Thread overview
A array bug?
Jan 28, 2009
taqya
Jan 28, 2009
Ellery Newcomer
Feb 05, 2009
Stewart Gordon
Feb 05, 2009
taqya
Feb 06, 2009
Stewart Gordon
January 28, 2009
Hi,i write this code. then d compiler is shutdown.
Is it a array bug?

//Digital Mars D Compiler v2.014 (windows)
import std.stdio;
int main()
{
	char[] a = "a".dup;
	char[] b = "b".dup;
	writefln(a + b); //Error: Array operations not implemented
	return 0;
}
January 28, 2009
taqya wrote:
> Hi,i write this code. then d compiler is shutdown.
> Is it a array bug?
> 
> //Digital Mars D Compiler v2.014 (windows)
> import std.stdio;
> int main()
> {
> 	char[] a = "a".dup;
> 	char[] b = "b".dup;
> 	writefln(a + b); //Error: Array operations not implemented
> 	return 0; 		 }

'+' implies you're trying to add "a" and "b" together e.g.
(char)((int) 'a' + (int) 'b')

If so, the error informs you why you can't do that.

If you're trying to concatenate, use the '~' operator.

assert ( "a" ~ "b" == "ab" );
February 05, 2009
Ellery Newcomer wrote:
> taqya wrote:
<snip>
>>     char[] a = "a".dup;
>>     char[] b = "b".dup;
>>     writefln(a + b); //Error: Array operations not implemented
<snip>
> If so, the error informs you why you can't do that.
<snip>

Except that it doesn't.  "Array operations not implemented" is a leftover from a previous version of the D spec.  Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof.  So the bug is that the error message is badly written.

Stewart.
February 05, 2009
Stewart Gordon wrote:
> Ellery Newcomer wrote:
>> taqya wrote:
> <snip>
>>>     char[] a = "a".dup;
>>>     char[] b = "b".dup;
>>>     writefln(a + b); //Error: Array operations not implemented
> <snip>
>> If so, the error informs you why you can't do that.
> <snip>
> 
> Except that it doesn't.  "Array operations not implemented" is a leftover from a previous version of the D spec.  Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof.  So the bug is that the error message is badly written.
> 
> Stewart.

Suggest: Array operation '<OP>' not implemented for type <T>[].

Where <OP> is here '+' and <T> is here char.

And possibly catch the particular case of char[] and suggest '~', since it is probably the single most common mistake in this area.

-- Chris Nicholson-Sauls
February 05, 2009
Chris Nicholson-Sauls Wrote:

> Stewart Gordon wrote:
> > Ellery Newcomer wrote:
> >> taqya wrote:
> > <snip>
> >>>     char[] a = "a".dup;
> >>>     char[] b = "b".dup;
> >>>     writefln(a + b); //Error: Array operations not implemented
> > <snip>
> >> If so, the error informs you why you can't do that.
> > <snip>
> > 
> > Except that it doesn't.  "Array operations not implemented" is a leftover from a previous version of the D spec.  Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof.  So the bug is that the error message is badly written.
> > 
> > Stewart.
> 
> Suggest: Array operation '<OP>' not implemented for type <T>[].
> 
> Where <OP> is here '+' and <T> is here char.
> 
> And possibly catch the particular case of char[] and suggest '~', since it is probably the single most common mistake in this area.
> 
> -- Chris Nicholson-Sauls


import std.stdio;
void main()
{
	char[] a = "a".dup;
	char[] b = "b".dup;
	writefln(a+b);
}

I compile the code on Windows. Then pop up a message 'dmd.exe has stopped working'. my personal situation?



February 06, 2009
Chris Nicholson-Sauls wrote:
<snip>
> Suggest: Array operation '<OP>' not implemented for type <T>[].
> 
> Where <OP> is here '+' and <T> is here char.

It doesn't quite work like that.  AIUI the only supported way of using array operations is assigning the result to an array slice, which this isn't.

> And possibly catch the particular case of char[] and suggest '~', since it is probably the single most common mistake in this area.

Maybe....

Stewart.
February 06, 2009
Stewart Gordon wrote:
> Chris Nicholson-Sauls wrote:
> <snip>
>> Suggest: Array operation '<OP>' not implemented for type <T>[].
>>
>> Where <OP> is here '+' and <T> is here char.
> 
> It doesn't quite work like that.  AIUI the only supported way of using array operations is assigning the result to an array slice, which this isn't.
> 

Just double-checked the spec, and yes, array ops are triggered by a slice appearing as an lvalue.  So, a different error message entirely is warranted.

-- Chris Nicholson-Sauls