Thread overview | |||||
---|---|---|---|---|---|
|
July 22, 2018 Bug? opIn with associative array keyed on static arrays | ||||
---|---|---|---|---|
| ||||
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 |
July 22, 2018 Re: Bug? opIn with associative array keyed on static arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | 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. */
}
----
|
July 23, 2018 Re: Bug? opIn with associative array keyed on static arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | 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 |
Copyright © 1999-2021 by the D Language Foundation