www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - AssociativeArray.opIndex

reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
In attempting to fix issue 5030, I'm finding that defining
AssociativeArray.opIndex gives an odd error when druntime is compiled:

dmd: mtype.c:4411: StructDeclaration* TypeAArray::getImpl(): Assertion `impl'
failed.

This error only happens when opIndex is declared like this:

	Value opIndex(Key key, int file=__FILE__, int line=__LINE__)

It seems to be OK when declared without the extra parameters, but then
if there's any error in the function body, such as a missing return
value, another strange error happens:

	src/core/thread.d(2835): Error: undefined identifier module thread.keys

Even though the error has nothing to do with thread.d at all.
Apparently there are some unstated assumptions about what's in struct
AssociativeArray?


T

-- 
Chance favours the prepared mind. -- Louis Pasteur
Mar 02 2012
next sibling parent "David Nadlinger" <see klickverbot.at> writes:
On Saturday, 3 March 2012 at 05:42:19 UTC, H. S. Teoh wrote:
 dmd: mtype.c:4411: StructDeclaration* TypeAArray::getImpl(): 
 Assertion `impl' failed.
 […]
 	src/core/thread.d(2835): Error: undefined identifier module 
 thread.keys
These two error messages indicate that the AssociativeArray template couldn't be instantiated (could be more explicit, I know, but DMD currently assumes it always works. To see what's wrong, you can explicitly instantiate it as AssociativeArray!(Key, Value), so that you'll get to see the actual error messages. David
Mar 03 2012
prev sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message 
news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...
 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above! If you're messing with dmd, try editing 'verror' to print error messages while gagged and it should show up.
Mar 03 2012
next sibling parent Alix Pexton <alix.DOT.pexton gmail.DOT.com> writes:
On 03/03/2012 11:50, Daniel Murphy wrote:
 "H. S. Teoh"<hsteoh quickfur.ath.cx>  wrote in message
 news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...
 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above! If you're messing with dmd, try editing 'verror' to print error messages while gagged and it should show up.
I checked the language reference, __FILE__ seems to be a little under documented ^^ A...
Mar 03 2012
prev sibling next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Mar 03, 2012 at 10:50:10PM +1100, Daniel Murphy wrote:
 "H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message 
 news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...
 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above!
[...] Ah, that's why I'm getting weird error messages. Silly mistake, should be string file=__FILE__. :-) Why are errors gagged in this case tho? T -- Doubtless it is a good thing to have an open mind, but a truly open mind should be open at both ends, like the food-pipe, with the capacity for excretion as well as absorption. -- Northrop Frye
Mar 03 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message 
news:mailman.350.1330790511.24984.digitalmars-d puremagic.com...
 On Sat, Mar 03, 2012 at 10:50:10PM +1100, Daniel Murphy wrote:
 "H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message
 news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...
 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above!
[...] Ah, that's why I'm getting weird error messages. Silly mistake, should be string file=__FILE__. :-) Why are errors gagged in this case tho?
(I think) because in most cases when semantic on AssocitiveArray fails, it's because the user tried to create an invalid AA and error messages for it should have already been issued. Eg an AA of type void[void] wouldn't compile, but error messages from the struct in object.d would just be confusing noise.
Mar 03 2012
prev sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday, March 03, 2012 22:50:10 Daniel Murphy wrote:
 "H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message
 news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...
 
 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above!
There are two of them, not one. file is supposed to be a string, and line should be a size_t - though in this particular case, using int for line probably won't result in a compilation error. It's still not correct though - especially when you end up in situations where someone actually gives an argument to line rather than letting it be the default. - Jonathan M Davis
Mar 03 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
"Jonathan M Davis" <jmdavisProg gmx.com> wrote in message 
news:mailman.354.1330804749.24984.digitalmars-d puremagic.com...
 On Saturday, March 03, 2012 22:50:10 Daniel Murphy wrote:
 "H. S. Teoh" <hsteoh quickfur.ath.cx> wrote in message
 news:mailman.341.1330753339.24984.digitalmars-d puremagic.com...

 Value opIndex(Key key, int file=__FILE__, int line=__LINE__)
The AssociateArray stuct has semantic run on it with errors gagged. Spot the error in the line above!
There are two of them, not one. file is supposed to be a string, and line should be a size_t - though in this particular case, using int for line probably won't result in a compilation error. It's still not correct though - especially when you end up in situations where someone actually gives an argument to line rather than letting it be the default. - Jonathan M Davis
Yeah well, there are several levels between something being wrong and something being correct. Using int instead of string is definately wrong, while using int instead of size_t is only wrong on 64bit, or 32bit when you're using really really really long files.
Mar 03 2012