www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug? opIn with associative array keyed on static arrays

reply Peter Alexander <peter.alexander.au gmail.com> writes:
void main() {
	int[int[1]] aa;
	aa[[2]] = 1;
	assert([2] in aa);
}

---

This assertion fails in 2081.1. Is this a bug?

https://dpaste.dzfl.pl/d4c0d4607482
Jul 22 2018
next sibling parent ag0aep6g <anonymous example.com> writes:
On Sunday, 22 July 2018 at 19:42:45 UTC, Peter Alexander wrote:
 void main() {
 	int[int[1]] aa;
 	aa[[2]] = 1;
 	assert([2] in aa);
 }

 ---

 This assertion fails in 2081.1. Is this a bug?
Definitely. Looks like `[2]` makes a dynamic array (length + pointer) and `in` reinterprets it as an `int[1]`. More examples: ---- void main() { int[int[1]] aa = [[2]: 1]; assert([123, 456] in aa); /* Passes. Shouldn't even compile. */ size_t[] dynarr = [1, 2, 3]; string[size_t[2]] aa2 = [[3, cast(size_t) dynarr.ptr]: "Wat."]; assert(*(dynarr in aa2) == "Wat."); /* Passes. Shouldn't even compile. */ } ----
Jul 22 2018
prev sibling parent Peter Alexander <peter.alexander.au gmail.com> writes:
On Sunday, 22 July 2018 at 19:42:45 UTC, Peter Alexander wrote:
 void main() {
 	int[int[1]] aa;
 	aa[[2]] = 1;
 	assert([2] in aa);
 }

 ---

 This assertion fails in 2081.1. Is this a bug?

 https://dpaste.dzfl.pl/d4c0d4607482
https://issues.dlang.org/show_bug.cgi?id=19112
Jul 23 2018