Skip to content

Commit

Permalink
Merge pull request #597 from 9rnsr/fix4523
Browse files Browse the repository at this point in the history
Issue 4523 - [tdpl] .remove method for Associative Arrays returns void in all cases
  • Loading branch information
WalterBright committed Jan 9, 2012
2 parents d12b1d2 + f3cc754 commit 1f14a6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -11503,7 +11503,7 @@ int InExp::isBit()
RemoveExp::RemoveExp(Loc loc, Expression *e1, Expression *e2)
: BinExp(loc, TOKremove, sizeof(RemoveExp), e1, e2)
{
type = Type::tvoid;
type = Type::tboolean;
}

void RemoveExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
Expand Down
2 changes: 1 addition & 1 deletion src/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -5715,7 +5715,7 @@ Expression *RemoveExp::interpret(InterState *istate, CtfeGoal goal)
}
valuesx->dim = valuesx->dim - removed;
keysx->dim = keysx->dim - removed;
return EXP_VOID_INTERPRET;
return new IntegerExp(loc, removed?1:0, Type::tbool);
}


Expand Down
60 changes: 43 additions & 17 deletions test/runnable/testaa2.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,7 @@

extern(C) int printf(const char*, ...);

int main()
{
testaa();
bug1899();
printf("Success\n");
return 0;
}

void testaa()
{
size_t i = foo("abc");
printf("i = %d\n", i);
assert(i == 0);

foo2();
}
/************************************************/

int a[string];

Expand Down Expand Up @@ -81,7 +66,18 @@ void foo2()
assert(c.length == 0);
}

void bug1899()
void testaa()
{
size_t i = foo("abc");
printf("i = %d\n", i);
assert(i == 0);

foo2();
}

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

void test1899()
{
int[3][string] AA;
int[3] x = [5,4,3];
Expand All @@ -90,3 +86,33 @@ void bug1899()
AA["def"] = [1,2,3];
assert(AA["def"]==[1,2,3]);
}

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

void foo4523()
{
int[string] aa = ["test":0, "test2":1];

bool found = aa.remove("test");
assert(found);
bool notfound = aa.remove("nothing");
assert(!notfound);
}

void test4523()
{
foo4523();
static assert({ foo4523(); return true; }());
}

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

int main()
{
testaa();
test1899();
test4523();

printf("Success\n");
return 0;
}

0 comments on commit 1f14a6e

Please sign in to comment.