Don't allow void as a value of an associative array.
text/plain
295
Comments
Comment #0 by pop.atry — 2007-10-21T22:37:48Z
alias void[int] IntSet;
void main(){
IntSet intSet;
intSet[6] = void;
intSet.remove(6);
}
IntSet.d(4): found ';' when expecting '.' following 'void'
Comment #1 by davidl — 2007-10-23T20:19:05Z
void is not a value but a type.
intSet[6] = void; <--- seems you want to assign void to intSet[6]?
Comment #2 by pop.atry — 2007-10-23T22:38:33Z
alias void[int] IntSet;
void makeVoid(){}
void main(){
IntSet intSet;
intSet[6] = makeVoid();
intSet.remove(6);
}
But this one also does not work.
Comment #3 by pop.atry — 2007-10-23T22:40:57Z
There should be a way to insert a key to void[int].
Comment #4 by ddparnell — 2007-10-23T23:37:57Z
I think that the bug is that void arrays are permitted at all. What exactly is an array of nothings? And if you had one, does it take up any memory.
If what you are asking for is a set of hashed keys, then use...
bool[int]
or
byte[int]
At least these mean something.
What exactly are you expecting to be able to set a void to?
Comment #5 by smjg — 2007-11-08T15:09:15Z
Fails with DMD 1.023 - so the problem is obviously in the DMD front end.
Comment #6 by bugs-d — 2008-01-24T00:06:51Z
Created attachment 221
Don't allow void as a value of an associative array.
I can't imagine how this could work, since the in operator would be useless (how can you return a pointer to a void?) It should simply be rejected.
-[Unknown]
Comment #7 by dlang-bugzilla — 2008-01-24T04:52:32Z
I disagree - IMO it should return a bool, because the "in" operator is more often used to check if the key is part of the AA/set. I think sets are used commonly enough to be part of the base language, and not just achievable through the less efficient dummytype[type] hack. While I agree with the void[type] declaration syntax, I think adding new values should be done through a .add() "method", which would be in line with .remove().
Comment #8 by clugdbug — 2010-05-22T07:06:43Z
*** Issue 3892 has been marked as a duplicate of this issue. ***
Comment #9 by clugdbug — 2010-11-08T08:25:31Z
The "should be a hash set" enhancement is WONTFIX. The bug is fixed in svn 742 for DMD1, and in svn 741 for D2.
Comment #10 by bearophile_hugs — 2010-11-08T09:45:49Z