Bug? opIn with associative array keyed on static arrays
ag0aep6g
anonymous at example.com
Sun Jul 22 22:22:41 UTC 2018
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. */
}
----
More information about the Digitalmars-d
mailing list