Bug 7129 – Compiling certain nested structs with -inline causes error "*** is a nested function and cannot be accessed from ***"

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2011-12-18T15:27:00Z
Last change time
2013-06-10T05:46:20Z
Assigned to
nobody
Creator
torarind

Comments

Comment #0 by torarind — 2011-12-18T15:27:19Z
This regression was introduced with the 2.057 release. I first hit the issue with code resembling the following: --------------------------------------------------------- import std.stdio, std.algorithm; void main() { writeln(filter!"a != 'r'"("Merry Christmas!")); } -------------------------------------------------------- Compiling with -inline gives: /src/phobos/std/algorithm.d(1120): Error: function std.algorithm.filter!("a != 'r'").filter!(string).filter is a nested function and cannot be accessed from formatValue This reduced test case gives a clue as to what is going on: --------------------------------------------------------- auto fun() { struct Result { this(int u) {} auto bar() { return Result(0); } } return Result(); } void main() { auto t = fun(); auto a = t.bar(); } --------------------------------------------------------- Compiled with -inline: t.d(7): Error: function t.fun is a nested function and cannot be accessed from main It seems what is happening is that bar is being inlined in main, but dmd doesn't know where to get the new fun.Result's context pointer from.
Comment #1 by bearophile_hugs — 2011-12-18T16:52:12Z
Isn't this in Bugzilla already?
Comment #2 by torarind — 2011-12-18T17:27:59Z
I can't find any mention of this error in conjunction with the inline switch.
Comment #3 by clugdbug — 2011-12-21T14:36:24Z
This isn't a regression. The reduced test case behaved the same in 2.026, which was the first version that could compile 'auto' functions. This is probably a duplicate of bug 4724 (which involves -inline). Could also be a dup of bug 4286 or bug 4841 (which involves -inline, but uses delegates and alias templates) Bug 5941 seems to be simplest test case for this species of bug.
Comment #4 by nilsbossung — 2013-01-26T01:33:38Z
Can't reproduce with the original test case, but this version still fails: auto fun() { int i; struct Result { this(int u) {} auto bar() { i = 42; } } return Result(); } void main() { auto t = fun(); t.bar(); }
Comment #5 by verylonglogin.reg — 2013-06-10T05:46:20Z
Mark it as a duplicate and add failing test from Comment 4 to Issue 4841. *** This issue has been marked as a duplicate of issue 4841 ***