[Issue 20448] New: Error: unknown when mutating an escaped member reference from a template function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 13 14:31:08 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20448
Issue ID: 20448
Summary: Error: unknown when mutating an escaped member
reference from a template function
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: mipri at minimaltype.com
The following complete program
```
import std.stdio : writeln;
struct S {
int x, y;
}
ref int member(string mem)(S p) {
return p.x;
}
void main() {
S p;
//writeln(p.member!"x");
p.member!"x" = 2;
writeln(p);
}
```
fails to compile with this error:
Error: unknown, please file report on issues.dlang.org
With the mutation commented out, and the writeln uncommented, it fails more
gracefully:
./x271.d(11): Error: returning p.x escapes a reference to parameter p, perhaps
annotate with return
./x271.d(16): Error: template instance x271.member!"x" error instantiating
Meanwhile a non-template version also has a proper error message:
```
import std.stdio : writeln;
struct S {
int x, y;
}
ref int member(S p) {
return p.x;
}
void main() {
S p;
p.member = 2;
writeln(p);
}
```
./x272.d(10): Error: returning p.x escapes a reference to parameter p, perhaps
annotate with return
--
More information about the Digitalmars-d-bugs
mailing list