Skip to content

Commit

Permalink
Merge pull request dlang#2927 from Geod24/what-the-heck-seriously
Browse files Browse the repository at this point in the history
Fix issue 20559: AA.clear segfault when used with alias this
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Feb 4, 2020
2 parents 20f5c09 + 261124f commit 3915d8e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/object.d
Expand Up @@ -2163,13 +2163,13 @@ alias AssociativeArray(Key, Value) = Value[Key];
* Params:
* aa = The associative array.
*/
void clear(T : Value[Key], Value, Key)(T aa)
void clear(Value, Key)(Value[Key] aa)
{
_aaClear(*cast(AA *) &aa);
}

/* ditto */
void clear(T : Value[Key], Value, Key)(T* aa)
void clear(Value, Key)(Value[Key]* aa)
{
_aaClear(*cast(AA *) aa);
}
Expand All @@ -2182,6 +2182,25 @@ void clear(T : Value[Key], Value, Key)(T* aa)
assert("k1" !in aa);
}

// Issue 20559
@system unittest
{
static class Foo
{
int[string] aa;
alias aa this;
}

auto v = new Foo();
v["Hello World"] = 42;
v.clear;
assert("Hello World" !in v);

// Test for T*
static assert(!__traits(compiles, (&v).clear));
static assert( __traits(compiles, (*(&v)).clear));
}

/***********************************
* Reorganizes the associative array in place so that lookups are more
* efficient.
Expand Down

0 comments on commit 3915d8e

Please sign in to comment.