Understanding DIP 1000 semantics -- Where's the bug?

Mike Franklin slavo5150 at yahoo.com
Sun Sep 22 17:17:40 UTC 2019


On Sunday, 22 September 2019 at 17:01:59 UTC, Mike Franklin wrote:
> On Sunday, 22 September 2019 at 16:32:02 UTC, Jacob Carlborg 
> wrote:
>> On 2019-09-22 13:22, Mike Franklin wrote:
>>
>>> Ok, that is an interesting observation.  If that's the case, 
>>> then I don't see any reason to ever annotate a `ref` 
>>> parameter with `scope`.  In other words, for `ref` parameters 
>>> `scope` is inferred (or implied).  Do you agree with that?
>>
>> Yes.
>
> According to DIP1000 
> (https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md#identity-function) `scope ref` is a thing, so I guess `scope` can't be inferred or implied for `ref`.
>
> I don't know.  I think Walter is the only one that can clear 
> this up.

Yes, `scope ref` is definitely a thing.  Compare the following.

// Exhibit C
@safe:

struct A
{
      int* ptr;
}

int* gptr;

void foo(ref A a)
{
      gptr = a.ptr; // error, can't leak borrowed a.ptr into 
global context
}

https://run.dlang.io/is/ZU780c


// Exhibit D
@safe:

struct A
{
      int* ptr;
}

int* gptr;

void foo(scope ref A a)
{
      gptr = a.ptr; // error, can't leak borrowed a.ptr into 
global context
}

https://run.dlang.io/is/ZU780c

This was taken from the discussion at 
https://forum.dlang.org/post/twgsrfcolypurgylhizh@forum.dlang.org


More information about the Digitalmars-d mailing list