Bug 20448 – Error: unknown when mutating an escaped member reference from a template function

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-12-13T14:31:08Z
Last change time
2019-12-18T05:08:17Z
Keywords
pull
Assigned to
No Owner
Creator
mipri

Comments

Comment #0 by mipri — 2019-12-13T14:31:08Z
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
Comment #1 by razvan.nitu1305 — 2019-12-16T13:58:18Z
It looks like an UFCS problem. Using `member!"x"(p)` instead of `p.member!"x"` yields the correct error message.
Comment #2 by dlang-bot — 2019-12-17T13:48:40Z
@RazvanN7 created dlang/dmd pull request #10676 "Fix Issue 20448 - Error: unknown when mutating an escaped member reference from a template function" fixing this issue: - Fix Issue 20448 - Error: unknown when mutating an escaped member reference from a template function https://github.com/dlang/dmd/pull/10676
Comment #3 by dlang-bot — 2019-12-18T05:08:17Z
dlang/dmd pull request #10676 "Fix Issue 20448 - Error: unknown when mutating an escaped member reference from a template function" was merged into master: - 414460467bca449f5f28b44fe80ac8da5a0ea4ad by RazvanN7: Fix Issue 20448 - Error: unknown when mutating an escaped member reference from a template function https://github.com/dlang/dmd/pull/10676