www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Range violation with AAs

reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
At

https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

I have an array container.

Everything works as expected in all unittests except for the line 
at

https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L1649

that fails as

     core.exception.RangeError array_ex.d(1649): Range violation

and I have no clue why.

Is this a know problem with AA's with container-like structs as 
value types?
Oct 17 2016
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 10/17/2016 10:43 AM, Nordlöw wrote:
 At

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

 I have an array container.

 Everything works as expected in all unittests except for the line at

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L1649

 that fails as

     core.exception.RangeError array_ex.d(1649): Range violation

 and I have no clue why.

 Is this a know problem with AA's with container-like structs as value
 types?
So, x is a user-defined type and the line that fails is x["a"] ~= 42; Unfortunately, as far as I know, that's a privilege reserved for built-in AAs. It still feels like x["a"] could return a proxy that could later add a new element and then apply ~= on it. (I haven't read the rest of your code to see whether you've already done that.) Ali
Oct 17 2016
next sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote:
 Unfortunately, as far as I know, that's a privilege reserved 
 for built-in AAs.
But I *am* using a built-in AA. The problem happens when the value is an instance of an `Array!T`-container and not a slice `T[]`.
Oct 17 2016
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 10/17/2016 11:28 AM, Nordlöw wrote:
 On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote:
 Unfortunately, as far as I know, that's a privilege reserved for
 built-in AAs.
But I *am* using a built-in AA. The problem happens when the value is an instance of an `Array!T`-container and not a slice `T[]`.
Sorry... :/ As a consolation :) there are two unrelated issues in your code, which a new dmd warns about: Deprecation: Implicit string concatenation is deprecated 1) Probably a missing comma after `mark`: enum nonStateHTMLTags = [`b`, `i`, `strong`, `em`, `sub`, `sup`, `small`, `ins`, `del`, `mark` `code`, `kbd`, `samp`, `samp`, `var`, `pre`]; 2) Missng ~ here: `<mn mathsize="80%">` ~ zexp ~ `</mn>` `</msup>` ~ Ali
Oct 17 2016
parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 17 October 2016 at 18:38:30 UTC, Ali Çehreli wrote:
 As a consolation :) there are two unrelated issues in your 
 code, which a new dmd warns about:

   Deprecation: Implicit string concatenation is deprecated

 1) Probably a missing comma after `mark`:

 enum nonStateHTMLTags = [`b`, `i`, `strong`, `em`, `sub`, 
 `sup`, `small`, `ins`, `del`, `mark`
                          `code`, `kbd`, `samp`, `samp`, `var`, 
 `pre`];

 2) Missng ~ here:

                         `<mn mathsize="80%">` ~ zexp ~ `</mn>`
                         `</msup>` ~
Thanks, anyway! Fixed!
Oct 17 2016
prev sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote:
 It still feels like x["a"] could return a proxy that could 
 later add a new element and then apply ~= on it. (I haven't 
 read the rest of your code to see whether you've already done 
 that.)
`Array` is in essence a C++-style array container (pointer, length, capacity) with C-style memory management. Nothing else. Have I done something wrong with ~= overloads perhaps?
Oct 17 2016
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 10/17/2016 11:40 AM, Nordlöw wrote:
 On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote:
 It still feels like x["a"] could return a proxy that could later add a
 new element and then apply ~= on it. (I haven't read the rest of your
 code to see whether you've already done that.)
`Array` is in essence a C++-style array container (pointer, length, capacity) with C-style memory management. Nothing else. Have I done something wrong with ~= overloads perhaps?
opOpAssign? (I need to stop guessing without coding. :) ) Ali
Oct 17 2016
prev sibling next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 17 October 2016 at 17:43:19 UTC, Nordlöw wrote:
 At

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

 I have an array container.

 Everything works as expected in all unittests except for the 
 line at

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L1649

 that fails as

     core.exception.RangeError array_ex.d(1649): Range violation

 and I have no clue why.

 Is this a know problem with AA's with container-like structs as 
 value types?
In other words alias Key = string; alias A = Array!int; A[Key] x; x["a"] ~= 42; // triggers violation fails. If I initialize the value prior to append as in alias Key = string; alias A = Array!int; A[Key] x; x["a"] = A.init; x["a"] ~= 42; // no violation the violation doesn't happen. And if I replace `Array!int` with `int[]` as in alias Key = string; alias A = int[]; A[Key] x; x["a"] ~= 42; it also doesn't happen.
Oct 17 2016
prev sibling next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 10/17/16 1:43 PM, Nordlöw wrote:
 At

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

 I have an array container.

 Everything works as expected in all unittests except for the line at

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L1649

 that fails as

     core.exception.RangeError array_ex.d(1649): Range violation

 and I have no clue why.
This seems like a bug. If RangeError is happening there, this means it's the AA that's complaining, not the Array!int. If this works properly with normal arrays, it means something is wrong in the way the AA behaves. Just another issue with our AA magic, I guess. -Steve
Oct 17 2016
prev sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Monday, 17 October 2016 at 17:43:19 UTC, Nordlöw wrote:
 At

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d

 I have an array container.

 Everything works as expected in all unittests except for the 
 line at

 https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L1649

 that fails as

     core.exception.RangeError array_ex.d(1649): Range violation

 and I have no clue why.

 Is this a know problem with AA's with container-like structs as 
 value types?
The same unittest with another Array (i.e not the one from phobos-next) gives the same error, so this confirms the other answer saying that's may be a builtin AA bug. Just a question, maybe off topic, does this work: unittest { alias Key = string; alias A = Array!int; A[Key] x; x["a"] = [0]; } ?
Oct 17 2016
parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 17 October 2016 at 19:10:54 UTC, Basile B. wrote:
 Just a question, maybe off topic, does this work:

 unittest
 {
     alias Key = string;
     alias A = Array!int;
     A[Key] x;
     x["a"] = [0];
 }

 ?
No, that works. Thanks for your interest.
Oct 17 2016