Understanding DIP 1000 semantics -- Where's the bug?
Mike Franklin
slavo5150 at yahoo.com
Sun Sep 22 10:24:39 UTC 2019
On Sunday, 22 September 2019 at 10:09:14 UTC, Sebastiaan Koppe
wrote:
>> 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
> }
> ---
I wouldn't say that `scope` only works for pointers, but rather
`scope` only works for references (i.e. pointers and `ref`
types). The issue is that `ref int i` behaves differently than
`int* i`. I understand that scope doesn't make any sense for
something like `int i` because it's not a "reference type" (for
lack of a better term).
More information about the Digitalmars-d
mailing list