Bug 5882 – Helper inner function in body{} and out{}

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-24T14:14:00Z
Last change time
2014-03-19T17:45:24Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-04-24T14:14:36Z
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() {}
Comment #1 by lt.infiltrator — 2014-03-19T17:45:24Z
*** This issue has been marked as a duplicate of issue 4699 ***