Skip to content

Commit

Permalink
Merge pull request #4008 from 9rnsr/fix13515
Browse files Browse the repository at this point in the history
[REG2.064] Issue 13515 - "Range violation" when writing to array of AAs from static this
  • Loading branch information
WalterBright committed Sep 25, 2014
2 parents f2fcc13 + 20ced52 commit a577e32
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -10984,6 +10984,16 @@ Expression *AssignExp::semantic(Scope *sc)
{
//printf("[%s] change to init - %s\n", loc.toChars(), toChars());
op = TOKconstruct;

// Bugzilla 13515: set Index::modifiable flag for complex AA element initialization
if (e1->op == TOKindex &&
((IndexExp *)e1)->e1->type->toBasetype()->ty == Taarray)
{
Expression *e1x = e1->modifiableLvalue(sc, e1old);
if (e1x->op == TOKerror)
return e1x;
e1 = e1x;
}
}

/* If it is an assignment from a 'foreign' type,
Expand Down
31 changes: 31 additions & 0 deletions test/runnable/sctor.d
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,44 @@ void test11246()
assert(Foo11246.dtor == 1);
}

/***************************************************/
// 13515

Object[string][100] aa13515;

static this()
{
aa13515[5]["foo"] = null;
}

struct S13515
{
Object[string][100] aa;

this(int n)
{
aa[5]["foo"] = null;
}
}

void test13515()
{
assert(aa13515[5].length == 1);
assert(aa13515[5]["foo"] is null);

auto s = S13515(1);
assert(s.aa[5].length == 1);
assert(s.aa[5]["foo"] is null);
}

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

int main()
{
test8117();
test9665();
test11246();
test13515();

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

0 comments on commit a577e32

Please sign in to comment.