Re: inout auto ref escaping a reference to parameter, only errors with vibe Json type, or if inout is there.

2019-03-12 Thread aliak via Digitalmars-d-learn

On Monday, 11 March 2019 at 22:29:05 UTC, aliak wrote:

[...]


Here's a much reduces test case:

struct W(T) {}

struct S {
int* data;
}

template match1(alias handler) {
auto ref match1(T)(inout auto ref W!T w) {
return handler();
}
}

template match2(alias handler) {
auto match2(T)(auto ref W!T w) {
return match1!handler(w);
}
}

void main() {
W!int()
.match2!(() => S());
}




Re: inout auto ref escaping a reference to parameter, only errors with vibe Json type, or if inout is there.

2019-03-12 Thread aliak via Digitalmars-d-learn

On Monday, 11 March 2019 at 22:29:05 UTC, aliak wrote:

Hi,

I have an error that says "Error: returning `match1(opt)` 
escapes a reference to parameter `opt`, perhaps annotate with 
`return`".


[...]


Ok, I've found out something else. It only happens when you're 
returning a type that has an indirection. So instead of the Json 
type if we returned an S type where S was:


struct S {
  void[2] data;
}

We get the same error.