[Issue 5882] New: Helper inner function in body{} and out{}

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 24 14:18:17 PDT 2011


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

           Summary: Helper inner function in body{} and out{}
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2011-04-24 14:14:36 PDT ---
Let's say I have a function foo() that uses an inner function bar(). To test
the correctness of the result of foo() I have sometimes to use bar() in foo()
post-condition too:


void foo()
    in {
        void bar() {}
        bar();
    } out {
        void bar() {}
        bar();
    } body {
        void bar() {}
        bar();
    }
void main() {}


But in DMD 2.052 this is not allowed:
test.d(6): Error: declaration bar is already defined in another scope in foo
test.d(9): Error: declaration bar is already defined in another scope in foo


bar() is not available inside the post-condition and pre-condition:

void foo()
    in {
        bar();
    } out {
        bar();
    } body {
        void bar() {}
        bar();
    }
void main() {}

It gives:
test.d(3): Error: undefined identifier bar
test.d(5): Error: undefined identifier bar


So currently the workaround is to define bar() again, with different names:

void foo()
    in {
        void bar_in() {}
        bar_in();
    } out {
        void bar_out() {}
        bar_out();
    } body {
        void bar() {}
        bar();
    }
void main() {}

-- 
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