Bug 4757 – A forward reference error with return of inner defined struct
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-08-29T10:36:00Z
Last change time
2014-03-14T12:23:16Z
Keywords
pull
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-08-29T10:36:19Z
This is a problem with a return of inner defined struct, I don't know if this specific case is already present in Bugzilla. I think others are already present.
DMD 2.048 compiles and runs this code with no errors:
static struct Bar(T) {
void spam() {
foo(1);
}
}
Bar!T foo(T)(T) {
return Bar!T();
}
void main() {
foo(1);
}
But if I pull the Bar struct inside foo(), using auto as return type:
auto foo(T)(T) {
static struct Bar(T) {
void spam() {
foo(1);
}
}
return Bar!T();
}
void main() {
foo(1);
}
I receive at compile-time:
test.d(4): Error: forward reference to inferred return type of function call foo(1)
test.d(7): Error: template instance test.foo!(int).foo.Bar!(int) error instantiating
test.d(10): instantiated from here: foo!(int)
Comment #1 by dlang-bugzilla — 2014-03-07T06:59:46Z