How to use a char[] buffer in D

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 23 09:13:58 PDT 2016


On Thu, Jun 23, 2016 at 08:36:57AM -0700, H. S. Teoh via Digitalmars-d-learn wrote:
> On Thu, Jun 23, 2016 at 10:00:33AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
[...]
> > > On Wednesday, 22 June 2016 at 22:41:24 UTC, H. S. Teoh wrote:
[...]
> > > > Maybe try:
> > > > 
> > > >     if (buffer[] in myHash) { ... }
> > > > 
> > > > ?  Does that make a difference?
> > > > 
> > > > 
> > > > T
> > > 
> > > 
> > 
> > This seems like a bug in the runtime, or am I missing something?
> [...]
> 
> It might well be a bug. I'll take a look.
[...]

It is indeed a bug. It's caused by the AA implementation receiving a
static char array when it's expecting a string (immutable(char)[])
according to the declared key type of the AA.

Filed a bug for this:

	https://issues.dlang.org/show_bug.cgi?id=16199

The compiler should either reject indexing an AA with a char[n], or it
should automatically slice the char[n] so that the AA implementation
gets the correct type in the key argument.


T

-- 
Those who don't understand D are condemned to reinvent it, poorly. -- Daniel N


More information about the Digitalmars-d-learn mailing list