shared immutable issues

Ali Çehreli acehreli at yahoo.com
Mon Jul 23 10:37:03 PDT 2012


On 07/23/2012 10:21 AM, Enerqi wrote:
 > Hi
 >
 > I'm wondering what the state of the language/libraries are with regard
 > to shared/immutable qualifiers. I've tried to use std.concurrency and
 > had a lot of compile issues passing shared data around.
 > Even a simple case I'm finding issue with:
 >
 > ---------
 > import std.array;
 >
 > int main(string[] argv)
 > {
 > shared uint[] arr = stuffone();
 > return 0;
 > }
 >
 > shared uint[] stuffone()

Hmmm... I think that's a bug. It should be the equivalent of the 
following, which does work:

shared(uint[]) stuffone()
{
     shared uint[] arr = new shared (uint[1]);
     arr[0] = 1;
     return arr;
}

Note that no need to cast returned object any more.

 > Another case I couldn't construct an appender to shared data:
 > ---------
 > import std.array;
 >
 > int main(string[] argv)
 > {
 > Appender!(shared uint[]) app = std.array.appender!(shared uint[]);
 > return 0;
 > }
 > ---------
 > Compile error:
 >
 > Error: incompatible types for ((cast(shared(uint)*)arr) is
 > (cast(uint*)(*this._data).arr)): 'shared(uint)*' and 'uint*'
 > shared.d(6):

Appender does cast(Unqual!(T)) which removes the 'shared' qualifier. I 
think that should be considered a bug with Appender.

Ali



More information about the Digitalmars-d-learn mailing list