[Issue 19097] Extend Return Scope Semantics

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 1 07:43:39 UTC 2018


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

--- Comment #15 from Mike Franklin <slavo5150 at yahoo.com> ---
I think in my prior example, I may have overlooked the implicit `this` argument
for member functions.  Here I attempt to compensate.

//------------------------------------------------
// OK, only one possible *output*
int* f(return scope int* p);

// OK, only one possible *output*
void f(ref scope int* r, return scope int* p);

//------------------------------------------------
// Error: `return` must be disambiguated between `this` and `r`
void f(ref scope int* r1, ref scope int* r2, return scope int* p);

// OK, `return` has been disambiguated
void f(ref scope int* r1, ref scope int* r2, return(r1) scope int* p);
void f(ref scope int* r1, ref scope int* r2, return(r2) scope int* p);

//------------------------------------------------
// Error: `return` must be disambiguated between the return value
// and the `r` output parameter.
int* f(ref scope int* r, return scope int* p);

// OK, `return` has been disambiguated
int* f(ref scope int* r, return(r) scope int* p);

// OK, `return` has been disambiguated
// `return(return)` is pretty yucky, but I can't think of anything
// else right now.
int* f(ref scope int* r, return(return) scope int* p);

struct S
{
    // Error: `return` must be disambiguated between `this` and `r`
    this(ref scope int* r, return scope int* p);

    // OK, `return` has been disambiguated
    this(ref scope int* r, return(this) scope int* p);
    this(ref scope int* r, return(r) scope int* p);

    //------------------------------------------------
    // Error: `return` must be disambiguated between `this` and `r`
    void f(ref scope int* r, return scope int* p);

    // OK, `return` has been disambiguated
    void f(ref scope int* r, return(this) scope int* p);

    // OK, `return` has been disambiguated
    void f(ref scope int* r, return(r) scope int* p);

    //------------------------------------------------
    // Error: `return` must be disambiguated between `this`, `r1`, and `r2`
    void f(ref scope int* r1, ref scope int* r2, return scope int* p);

    // OK, `return` has been disambiguated
    void f(ref scope int* r1, ref scope int* r2, return(r1) scope int* p);
    void f(ref scope int* r1, ref scope int* r2, return(r2) scope int* p);

    //------------------------------------------------
    // Error: `return` must be disambiguated between `this` and the return
value
    int* f(return scope int* p);

    // OK, `return` has been disambiguated
    int* f(return(this) scope int* p);

    // OK, `return` has been disambiguated - tied to return value
    int* f(return(return) scope int* p);
}

Hopefully, you get the idea.

--


More information about the Digitalmars-d-bugs mailing list