[Issue 14788] New: Incorrect rejection of inout function call
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jul 8 06:14:00 PDT 2015
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 at puremagic.com
Reporter: k.hara.pg at 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.
--
More information about the Digitalmars-d-bugs
mailing list