[dmd 2.066-b1] std.range.array with shared objects and AA rehash
NCrashed via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 8 05:42:43 PDT 2014
On Monday, 7 July 2014 at 15:34:33 UTC, Meta wrote:
> On Monday, 7 July 2014 at 09:53:22 UTC, NCrashed wrote:
>> I am using ranges (wrapped in InputRangeObject for use in
>> interfaces) of shared objects, with new beta some cases are
>> broken:
>> ```
>> import std.range;
>>
>> class A {}
>>
>> InputRange!(shared A) foo()
>> {
>> return [new A].inputRangeObject;
>> }
>>
>> void bar()
>> {
>> auto res = foo.array;
>> }
>>
>> void main() {}
>> ```
>> Fails with:
>> ```
>> source/app.d(7): Error: cannot implicitly convert expression
>> (inputRangeObject([new A])) of type
>> std.range.InputRangeObject!(A[]).InputRangeObject to
>> std.range.InputRange!(shared(A)).InputRange
>> /usr/include/dmd/phobos/std/conv.d(3914): Error: cannot
>> implicitly convert expression (arg) of type shared(A) to app.A
>> /usr/include/dmd/phobos/std/array.d(2476): Error: template
>> instance
>> std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A)) error
>> instantiating
>> /usr/include/dmd/phobos/std/array.d(64): instantiated
>> from here: put!(shared(A))
>> source/app.d(12): instantiated from here:
>> array!(InputRange!(shared(A)))
>> ```
>>
>> And also AA starts behave strange in shared context:
>> ```
>> shared string[][string] map;
>>
>> void main()
>> {
>> map.rehash;
>> }
>> ```
>> My AA is stored in shared class, the shared is inferred
>> implicitly. Also following workaround works:
>> ```
>> void main()
>> {
>> (cast(shared(string[])[string])map).rehash;
>> }
>> ```
>>
>> Is this behavior a bug, or it works as expected?
>
> I don't know about your second problem, but the fix for your
> first problem is to construct a shared A. You're trying to
> create a normal A and have it implicitly casted to shared,
> which the compiler won't do.
>
> InputRange!(shared A) foo()
> {
> //"new shared A" instead of "new A"
> return [new shared A].inputRangeObject;
> }
Oops, I forgot shared at new. But the major issue is that doesn't
fix the problem:
```
import std.range;
class A {}
InputRange!(shared A) foo()
{
return [new shared A].inputRangeObject;
}
void bar()
{
auto res = foo.array;
}
void main() {}
```
Output:
```
/usr/include/dmd/phobos/std/conv.d(3914): Error: cannot
implicitly convert expression (arg) of type shared(A) to app.A
/usr/include/dmd/phobos/std/array.d(2476): Error: template
instance std.conv.emplaceRef!(shared(A)).emplaceRef!(shared(A))
error instantiating
/usr/include/dmd/phobos/std/array.d(64): instantiated from
here: put!(shared(A))
source/app.d(12): instantiated from here:
array!(InputRange!(shared(A)))
```
More information about the Digitalmars-d-learn
mailing list