Bug 14788 – Incorrect rejection of inout function call
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-08T13:14:00Z
Last change time
2016-03-19T20:21:48Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2015-07-08T13:14:00Z
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.
Comment #1 by k.hara.pg — 2015-07-16T14:25:58Z
(In reply to Kenji Hara from comment #0)
> This compiler bug is blocking fix for the regression issue 14626.
Now it's not required.