www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 790] New: arbitrary lookahead for nested functions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=790

           Summary: arbitrary lookahead for nested functions
           Product: D
           Version: 0.178
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: Daniel919 web.de


void main() {
        int a() { return b(1); }
        int b(int y = 0) { if (y == 0) return a(); else return y; }
        b();
}

line 2: Error: undefined identifier b

If you put the implementation of function a and b outside (into global scope),
then it's working.
So the lookahead is not working for nested functions.


-- 
Jan 03 2007
next sibling parent BCS <nothing pathlink.com> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=790
 
            Summary: arbitrary lookahead for nested functions
            Product: D
            Version: 0.178
           Platform: PC
         OS/Version: Windows
             Status: NEW
           Severity: normal
           Priority: P2
          Component: DMD
         AssignedTo: bugzilla digitalmars.com
         ReportedBy: Daniel919 web.de
 
 
 void main() {
         int a() { return b(1); }
         int b(int y = 0) { if (y == 0) return a(); else return y; }
         b();
 }
 
 line 2: Error: undefined identifier b
 
 If you put the implementation of function a and b outside (into global scope),
 then it's working.
 So the lookahead is not working for nested functions.
 
 

Look ahead on nested function is not allowed. Therefor this is according to spec. to quote: ----------- Unlike module level declarations, declarations within function scope are processed in order. This means that two nested functions cannot mutually call each other: void test() { void foo() { bar(); } // error, bar not defined void bar() { foo(); } // ok } The solution is to use a delegate: void test() { void delegate() fp; void foo() { fp(); } void bar() { foo(); } fp = &bar; } Future directions: This restriction may be removed. -------------
Jan 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=790


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Severity|normal                      |enhancement




------- Comment #1 from smjg iname.com  2007-01-03 19:33 -------
This is a documented restriction:

http://www.digitalmars.com/d/function.html#nested
"Unlike module level declarations, declarations within function scope are
processed in order. This means that two nested functions cannot mutually call
each other:"

Demoting to enhancement.


-- 
Jan 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=790


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |bugzilla digitalmars.com


--- Comment #2 from Andrei Alexandrescu <andrei metalanguage.com> 2010-11-26
14:11:51 PST ---
I personally think this should be just closed. Symbols defined inside a
functions obey sequential visibility. The decision is left to Walter.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 26 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=790


nfxjfg gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg gmail.com


--- Comment #3 from nfxjfg gmail.com 2010-11-26 15:05:03 PST ---
The D1 _and_ the D2 specs say about this issue: "Future directions: This
restriction may be removed.". Talk about one hand not knowing what the other
hand is doing.

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