Typeinfo inconsistencies

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Aug 13 10:41:03 PDT 2013


So, I got some free time today and decided to look into issue 6210, and
found out that the problem was caused by this:

	char[]        a = "h".dup;
	const(char)[] b = "h";
	string        c = "h";

	writeln(typeid(a).getHash(&a)); // prints 104
	writeln(typeid(b).getHash(&b)); // prints 703014434222502
	writeln(typeid(c).getHash(&c)); // prints 104

This is completely b0rken, because it causes the following code to fail:

	int[char[]] aa;
	aa["h"] = 1;

	assert(aa.dup == aa);	// fails

The reason for this inconsistency is that char[] and immutable(char)[]
(aka string) have their getHash functions overridden in druntime's
src/rt/typeinfo/ti_Ag.d, but there is no such override for
const(char)[].

I tried adding another subclass for const(char)[]'s typeid that inherits
the correct version of getHash, but it didn't work because presumably
this stuff is hardcoded into the compiler somewhere.

So my question is, where in the compiler decides to use the specific
typeinfos for char[] and immutable(char)[], but not const(char)[]?


T

-- 
That's not a bug; that's a feature!


More information about the Digitalmars-d mailing list