Bug 17931 – [scope] `return` == `return scope` breaks for struct methods

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-23T17:40:00Z
Last change time
2018-01-04T01:01:48Z
Keywords
safe
Assigned to
Walter Bright
Creator
Martin Nowak

Comments

Comment #0 by code — 2017-10-23T17:40:00Z
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`.