Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 17, 2016 Range violation with AAs | ||||
---|---|---|---|---|
| ||||
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? |
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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.
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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[]`.
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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?
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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!
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
October 17, 2016 Re: Range violation with AAs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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];
}
?
|
Copyright © 1999-2021 by the D Language Foundation