D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4757 - A forward reference error with return of inner defined struct
Summary: A forward reference error with return of inner defined struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2010-08-29 10:36 UTC by bearophile_hugs
Modified: 2014-03-14 12:23 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-08-29 10:36:19 UTC
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 Vladimir Panteleev 2014-03-07 06:59:46 UTC
https://github.com/D-Programming-Language/dmd/pull/3365
Comment 2 github-bugzilla 2014-03-14 12:22:21 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c23044e9d279b2e8d38909b15419e51843767c75
fix Issue 4757 - A forward reference error with return of inner defined struct

https://github.com/D-Programming-Language/dmd/commit/c015f0d2cd2aa24798838c583e2842e696c47466
Merge pull request #3365 from CyberShadow/fix4757

fix Issue 4757 - A forward reference error with return of inner defined struct