May 10
On 10.05.2017 15:18, Stefan Koch wrote:
>
> if you try assert([] is null), it should fail.

It doesn't. I have tried to make that point before, unsuccessfully.
Empty arrays may or may not be null, but the empty array literal is always null.
May 10
On Wednesday, 10 May 2017 at 14:13:09 UTC, Timon Gehr wrote:
> On 10.05.2017 15:18, Stefan Koch wrote:
>>
>> if you try assert([] is null), it should fail.
>
> It doesn't. I have tried to make that point before, unsuccessfully.
> Empty arrays may or may not be null, but the empty array literal is always null.
cat t3.d ----
static assert([] is null);
---
dmd t.d -c ---
t3.d(1): Error: static assert  ([] is null) is false
----
May 10
On 10.05.2017 16:21, Stefan Koch wrote:
> On Wednesday, 10 May 2017 at 14:13:09 UTC, Timon Gehr wrote:
>> On 10.05.2017 15:18, Stefan Koch wrote:
>>>
>>> if you try assert([] is null), it should fail.
>>
>> It doesn't. I have tried to make that point before, unsuccessfully.
>> Empty arrays may or may not be null, but the empty array literal is
>> always null.
> cat t3.d ----
> static assert([] is null);
> ---
> dmd t.d -c ---
> t3.d(1): Error: static assert  ([] is null) is false
> ----

void main(){
    import std.stdio;
    enum x = [] is null;
    auto y = [] is null;
    writeln(x," ",y); // "false true"
}

May 10
On Wednesday, 10 May 2017 at 18:41:30 UTC, Timon Gehr wrote:
> On 10.05.2017 16:21, Stefan Koch wrote:
>> On Wednesday, 10 May 2017 at 14:13:09 UTC, Timon Gehr wrote:
>>> On 10.05.2017 15:18, Stefan Koch wrote:
>>>>
>>>> if you try assert([] is null), it should fail.
>>>
>>> It doesn't. I have tried to make that point before, unsuccessfully.
>>> Empty arrays may or may not be null, but the empty array literal is
>>> always null.
>> cat t3.d ----
>> static assert([] is null);
>> ---
>> dmd t.d -c ---
>> t3.d(1): Error: static assert  ([] is null) is false
>> ----
>
> void main(){
>     import std.stdio;
>     enum x = [] is null;
>     auto y = [] is null;
>     writeln(x," ",y); // "false true"
> }

Oh fudge.
Another case where the ctfe-engine goes the right way;
And the runtime version does not ... we should fix this one of these days.
May 11
On 5/10/17 3:45 PM, Stefan Koch wrote:
> On Wednesday, 10 May 2017 at 18:41:30 UTC, Timon Gehr wrote:
>> On 10.05.2017 16:21, Stefan Koch wrote:
>>> On Wednesday, 10 May 2017 at 14:13:09 UTC, Timon Gehr wrote:
>>>> On 10.05.2017 15:18, Stefan Koch wrote:
>>>>>
>>>>> if you try assert([] is null), it should fail.
>>>>
>>>> It doesn't. I have tried to make that point before, unsuccessfully.
>>>> Empty arrays may or may not be null, but the empty array literal is
>>>> always null.
>>> cat t3.d ----
>>> static assert([] is null);
>>> ---
>>> dmd t.d -c ---
>>> t3.d(1): Error: static assert  ([] is null) is false
>>> ----
>>
>> void main(){
>>     import std.stdio;
>>     enum x = [] is null;
>>     auto y = [] is null;
>>     writeln(x," ",y); // "false true"
>> }
>
> Oh fudge.
> Another case where the ctfe-engine goes the right way;
> And the runtime version does not ... we should fix this one of these days.

[] lowers to a d runtime call (in lifetime, the function to allocate an array) with no elements.

The function must return a valid array with 0 length. null is such an array. It's not an error at all, and should not be fixed or changed IMO.

You almost never want to use 'is' on an array, as it compares just the pointer and length. Usually you want '=='.

For instance, you would never do:

[1, 2, 3] is [1, 2, 3]

And expect any sane result. It might actually be true on some compiler that's clever enough!

-Steve
Next ›   Last »
1 2 3