Permalink
Browse files

Issue 4523 - [tdpl] .remove method for Associative Arrays returns voi…

…d in all cases
  • Loading branch information...
1 parent 3912454 commit f3cc75445775927e2036054811afb686cf4f1624 @9rnsr committed Jan 2, 2012
Showing with 45 additions and 19 deletions.
  1. +1 −1 src/expression.c
  2. +1 −1 src/interpret.c
  3. +43 −17 test/runnable/testaa2.d
View
@@ -11891,7 +11891,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)
View
@@ -5685,7 +5685,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);
}
@@ -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];
@@ -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];
@@ -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 f3cc754

Please sign in to comment.