[Issue 17931] New: [scope] `return` == `return scope` breaks for struct methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 23 17:40:00 UTC 2017


https://issues.dlang.org/show_bug.cgi?id=17931

          Issue ID: 17931
           Summary: [scope] `return` == `return scope` breaks for struct
                    methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: bugzilla at digitalmars.com
          Reporter: code at dawg.eu

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.

--


More information about the Digitalmars-d-bugs mailing list