www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20209] New: AA.get() needs to work with inout correctly

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

          Issue ID: 20209
           Summary: AA.get() needs to work with inout correctly
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code:
------
struct C {
        int[] data;
}
struct S {
        private int[][string] aa;
        inout(C) func(string key) inout {
                return inout(C)(aa[key]);
        }
        inout(C) gunk(string key) inout {
                return inout(C)(aa.get(key, [])); // line 10
        }
}
------

Compiler output:
------
test.d(10): Error: cannot implicitly convert expression get(this.aa, key,
delegate const(int[])() pure nothrow  nogc  safe => []) of type const(int[]) to
inout(int[])
------

Expected behaviour: gunk() should compile, because it's doing nothing illegal:
it's looking up a key from S.aa and returning it, just like func() does, except
that gunk() uses aa.get() in order to provide a default value when the key
doesn't exist in the AA.

--
Sep 12 2019