Skip to content

Commit

Permalink
fix issue 19112 - Associative array opIn with static array key fails …
Browse files Browse the repository at this point in the history
…with dynamic array
  • Loading branch information
aG0aep6G committed Jul 23, 2018
1 parent e810f3f commit e1701d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dmd/expressionsem.d
Expand Up @@ -8923,7 +8923,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
TypeAArray ta = cast(TypeAArray)t2b;

// Special handling for array keys
if (!arrayTypeCompatible(exp.e1.loc, exp.e1.type, ta.index))
if (!arrayTypeCompatibleWithoutCasting(exp.e1.type, ta.index))
{
// Convert key to type of key
exp.e1 = exp.e1.implicitCastTo(sc, ta.index);
Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/test19112.d
@@ -0,0 +1,16 @@
/* TEST_OUTPUT:
---
fail_compilation/test19112.d(13): Error: cannot implicitly convert expression `[123, 456]` of type `int[]` to `int[1]`
fail_compilation/test19112.d(15): Error: cannot implicitly convert expression `a` of type `int[]` to `int[1]`
---
*/

// https://issues.dlang.org/show_bug.cgi?id=19112

void main()
{
int[int[1]] aa;
int* p = [123, 456] in aa;
int[] a;
p = a in aa;
}
15 changes: 15 additions & 0 deletions test/runnable/testaa.d
Expand Up @@ -1328,6 +1328,20 @@ void test14321()
assert(Bar.op == "d");
}

/************************************************/
// 19112

void test19112()
{
int[int[1]] aa;
aa[[2]] = 1;
assert([2] in aa);

int[int[]] aa2 = [[1, 2, 3]: 4];
int[3] k = [1, 2, 3];
assert(*(k in aa2) == 4);
}

/************************************************/

int main()
Expand Down Expand Up @@ -1379,6 +1393,7 @@ int main()
test11730();
test14089();
test14321();
test19112();

printf("Success\n");
return 0;
Expand Down

0 comments on commit e1701d7

Please sign in to comment.