Limit Scope Restriction? with dmd -dip25 -dip1000

Dennis dkorpel at gmail.com
Sat Apr 3 15:44:35 UTC 2021


On Saturday, 3 April 2021 at 15:32:38 UTC, apz28 wrote:
>     return foo.bytes(); // Error: scope variable foo assigned 
> to non-scope parameter this calling Foo.bytes

Add the `scope` storage class to your `bytes()` function to tell 
the compiler that the function won't escape any references to 
class members.
```D
      ubyte[] bytes() scope
      {
          return new ubyte[1];
      }
```

If you want the compiler to infer this, make it return `auto` or 
make it a template function.


More information about the Digitalmars-d mailing list