cat > bug.d << CODE
struct S
{
@safe S foo() return /* scope */
{
return this;
}
int* p; // so it has an indirection
}
void test(scope S s) @safe
{
s.foo;
}
CODE
dmd -c -dip1000 bug.d
----
bug.d(13): Error: scope variable s assigned to non-scope parameter this calling bug.S.foo
----
Introduced with https://github.com/dlang/dmd/pull/5909.
The above code can be compiled by using `return scope` instead, but in that case the `return scope` is still reduced to `return` in the mangling.
Maybe it's a problem with struct methods being implicity ref for the this parameter?
Hopefully we can consistently use `return` as abbreviation for `return scope`, if it depends on the context, then it might not be worth the confusion.
Comment #1 by code — 2018-01-04T01:01:48Z
Indeed `return` only means `return scope` when the parameters is not also `ref`.