Bug in the spec or implementation?
schveiguy at yahoo.com
Thu Aug 5 13:24:14 PDT 2010
On Thu, 05 Aug 2010 16:00:35 -0400, simendsjo <simen.endsjo at pandavre.com>
> On 05.08.2010 21:41, Steven Schveighoffer wrote:
>> On Thu, 05 Aug 2010 15:13:26 -0400, simendsjo
>> <simen.endsjo at pandavre.com> wrote:
>> I found this line in the spec:
>> "These issues also apply to concatenating arrays with the ~ and ~=
>> Where "These issues" refer to reallocating in place (look at the section
>> for setting the length of an array).
>> I think this line is in error, as it directly conflicts with the
>> "Concatenation always creates a copy of its operands, even if one of the
>> operands is a 0 length array"
>> I think the line should read:
>> "These issues also apply to appending arrays with the ~= operator. Note
>> that the concatenation operator ~ is not affected since it always
>> I can assure you that the runtime does always make a copy on
>> concatenation, and always tries to append in place if possible on an
>> expanding length or an append.
>> The spec needs some work, but the runtime is correct.
>> I will file a bug against the spec for you.
> Seems there are plenty of errors in the spec though...
> It will be very difficult to learn the language if the spec and
> implementation is different. Spec or compiler bug?
> char a = new char;
> char b = a[0..10];
> assert(a.ptr == b.ptr); // hmm.. does slice has a offset property or
> // In the spec on arrays#Setting Dynamic Array Length,
> // this is the example, but it doesn't work as in the spec...
> char c = a[10..20];
> // The spec says expanding b.length should expand
> // in place as a has enough memory and thus overlapping a, but...
> assert(b.capacity == 0); // capacity is 0, so...
> b.length = 15;
> assert(b.capacity == 15); // .. setting length removed it from a..
> assert(a.ptr == b.ptr); // fails...
> b = 'x'; // Says a and c should also change..
> assert(a == 'x'); // fails
> assert(c == 'x'); // fails
Yep, I noticed that too when going to file the bug :)
see here: http://d.puremagic.com/issues/show_bug.cgi?id=4590
I should take responsibility for not fixing this sooner since the runtime
used to work this way, but does not since a patch I added in 2.041 or
More information about the Digitalmars-d