Thread overview
Immutable immutable strings??
Feb 10, 2012
H. S. Teoh
Feb 10, 2012
Marco Leise
Feb 10, 2012
Timon Gehr
February 10, 2012
I'm not sure whether the following a compiler/language bug or a Phobos bug, but it's definitely some kind of bug:

	auto s = "abc";
	immutable t = "def";

	writeln(typeid(s));	// immutable(char)[]
	writeln(typeid(t));	// immutable(immutable(char)[])
				// (what is this supposed to mean?!)

	char ch = 'c';
	bool b = canFind(s, ch);	// OK
	bool c = canFind(t, ch);	// Compile error??

The compile error is:

test.d:11: Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if (is(typeof(find!(pred)(range,value)))) does not match any function template declaration
test.d:11: Error: template std.algorithm.canFind(alias pred = "a == b",Range,V) if (is(typeof(find!(pred)(range,value)))) cannot deduce template function from argument types !()(immutable(char[]),char)

Can somebody explain what's going on here?


T

-- 
There are two ways to write error-free programs; only the third one works.
February 10, 2012
Am 10.02.2012, 19:07 Uhr, schrieb H. S. Teoh <hsteoh@quickfur.ath.cx>:

> I'm not sure whether the following a compiler/language bug or a Phobos
> bug, but it's definitely some kind of bug:
>
> 	auto s = "abc";
> 	immutable t = "def";
>
> 	writeln(typeid(s));	// immutable(char)[]
> 	writeln(typeid(t));	// immutable(immutable(char)[])
> 				// (what is this supposed to mean?!)

That is supposed to mean that you can neither modify the values of the characters in the array nor the array itself:

t[1] = 'a'; // immutable(char)
t.length = 2; // immutable(...[])
February 10, 2012
On 02/10/2012 07:10 PM, Marco Leise wrote:
> Am 10.02.2012, 19:07 Uhr, schrieb H. S. Teoh <hsteoh@quickfur.ath.cx>:
>
>> I'm not sure whether the following a compiler/language bug or a Phobos
>> bug, but it's definitely some kind of bug:
>>
>> auto s = "abc";
>> immutable t = "def";
>>
>> writeln(typeid(s)); // immutable(char)[]
>> writeln(typeid(t)); // immutable(immutable(char)[])
>> // (what is this supposed to mean?!)
>
> That is supposed to mean that you can neither modify the values of the
> characters in the array nor the array itself:

immutable(char[]) does already say that.

>
> t[1] = 'a'; // immutable(char)
> t.length = 2; // immutable(...[])

It is a runtime bug, and has been discussed before, but I am not sure if it has been filed (probably yes). A similar bug has recently been fixed for the compiler's internal formatting exposed through error messages/.stringof:

http://d.puremagic.com/issues/show_bug.cgi?id=6941