Friends don't let friends use inout with scope and -dip1000

Steven Schveighoffer schveiguy at gmail.com
Tue Aug 21 14:04:15 UTC 2018


On 8/21/18 9:42 AM, Kagamin wrote:
> ....except for templated functions:
> 
> int[] escape(scope int[] r)
> {
>      return r; //error, can't return scoped argument
> }
> 
> int[] escape(return int[] r)
> {
>      return r; //ok, just as planned
> }
> 
> int[] escape(return scope int[] r)
> {
>      return r; //ok, `return scope` reduced to just `return`
> }
> 
> int[] escape(T)(scope int[] r)
> {
>      return r; //ok! `scope` silently promoted to `return`
> }
> 
> You can't have strictly scoped parameter in a templated function - it's 
> silently promoted to return parameter. Is this intended?

I would guess it's no different than other inferred attributes. I would 
also guess that it only gets promoted to a return parameter if it's 
actually returned.

As long as the *result* is scoped like the parameter. In the case of the 
OP in this thread, there is definitely a problem with inout and the 
connection to the return value.

-Steve


More information about the Digitalmars-d mailing list