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

Sebastiaan Koppe mail at skoppe.eu
Sun Sep 22 10:09:14 UTC 2019


On Sunday, 22 September 2019 at 07:54:12 UTC, Mike Franklin wrote:
>
> On Sunday, 22 September 2019 at 07:01:42 UTC, Sebastiaan Koppe 
> wrote:
>> I think that taking a reference of a local variable should 
>> result in a scope T*.
>>
>> In that case `&value` in `y ~= getValue1(&value);` should 
>> result in a scope int*.
>
> If that's the case then shouldn't Exhibit B (copied below for 
> convenience) require getValue2` to be `int getValue2(scope ref 
> int i)`?  If not, what's the justification?

scope only works on pointers.

---
@safe:

// Exhibit B
//--------------------------
struct P(T) {
     T t;
}

alias Value1 = P!(int);
alias Value2 = P!(int*);

Value1 getValue1(ref Value1 v) { return v; }
Value2 getValue2(ref Value2 v) { return v; }

void foo2()
{
     scope Value1 value1;
     scope Value2 value2;
     getValue1(value1); // No error
     getValue2(value2); // Error: scope variable value2 assigned 
to non-scope parameter v calling onlineapp.getValue2
}
---



More information about the Digitalmars-d mailing list