digitalmars.D.learn - Range violation with AAs
- =?UTF-8?B?Tm9yZGzDtnc=?= (11/11) Oct 17 2016 At
- =?UTF-8?Q?Ali_=c3=87ehreli?= (9/19) Oct 17 2016 So, x is a user-defined type and the line that fails is
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/6) Oct 17 2016 But I *am* using a built-in AA. The problem happens when the
- =?UTF-8?Q?Ali_=c3=87ehreli?= (13/18) Oct 17 2016 Sorry... :/
- =?UTF-8?B?Tm9yZGzDtnc=?= (2/13) Oct 17 2016 Thanks, anyway! Fixed!
- =?UTF-8?B?Tm9yZGzDtnc=?= (4/8) Oct 17 2016 `Array` is in essence a C++-style array container (pointer,
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/10) Oct 17 2016 opOpAssign? (I need to stop guessing without coding. :) )
- =?UTF-8?B?Tm9yZGzDtnc=?= (20/31) Oct 17 2016 In other words
- Steven Schveighoffer (6/14) Oct 17 2016 This seems like a bug. If RangeError is happening there, this means it's...
- Basile B. (13/24) Oct 17 2016 The same unittest with another Array (i.e not the one from
- =?UTF-8?B?Tm9yZGzDtnc=?= (3/12) Oct 17 2016 No, that works.
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
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
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
On 10/17/2016 11:28 AM, Nordlöw wrote:On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote: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>` ~ AliUnfortunately, 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
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
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
On 10/17/2016 11:40 AM, Nordlöw wrote:On Monday, 17 October 2016 at 18:22:53 UTC, Ali Çehreli wrote:opOpAssign? (I need to stop guessing without coding. :) ) AliIt 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
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
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
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
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