digitalmars.D.bugs - [Issue 14788] New: Incorrect rejection of inout function call
- via Digitalmars-d-bugs (41/41) Jul 08 2015 https://issues.dlang.org/show_bug.cgi?id=14788
https://issues.dlang.org/show_bug.cgi?id=14788 Issue ID: 14788 Summary: Incorrect rejection of inout function call Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: k.hara.pg gmail.com Blocks: 14626 Following code does not compile, but it should. auto make(K, V)(inout V[K] aa) { static struct Result { V[K] aa; ref front() inout { return aa[1]; } } return inout Result(aa); } void main() { int[int] aa = [1:1]; make(aa).front(); // line 14 } Output: $ dmd -o- test test.d(14): Error: modify inout to mutable is not allowed inside inout function ---- If the 'Result' struct is not static, the error is not wrong. Because the returned reference by Result.front() may come from the local state of enclosing 'make' function. However the 'Result' is actually static and it cannot access outer inout function context. Therefore the compile error is not correct. This compiler bug is blocking fix for the regression issue 14626. --
Jul 08 2015