[Issue 8862] order of declaration of a function and compile time execution

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 21 06:37:45 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8862


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #1 from bearophile_hugs at eml.cc 2012-10-21 06:37:26 PDT ---
Reduced test case. The the line of initialization of the 'b' variable matters.
If it's defined after bar() it compiles, otherwise it doesn't compile:


mixin template Foo() {
    static Spam[1] b = bar(); // Bad.
    static Spam[1] bar() {
        Spam[1] result;
        return result;
    }
    // static Spam[1] b = bar(); // Good.
}
struct Spam {
    mixin Foo!();
}
void main() {}


Initializing 'b' before defining bar() gives the errors:

test.d(3): Error: function test.Spam.Foo!().bar circular dependency. Functions
cannot be interpreted while being compiled
test.d(2):        called from here: bar()
test.d(2):        called from here: bar()
test.d(10): Error: mixin test.Spam.Foo!() error instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list