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





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



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



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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=790




Commit pushed to master at
https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/81a653a519c751973cf810a062e68ce997014a02
Explain how to forward-reference a nested function

Response to forum post 2012-4-3, "Nested functions should be exempt from
sequential visibility rules" and bug 790.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



This could be closed as invalid, but I'm
changing to a spec bug, and marking as fixed, since the spec was changed.

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


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |



Adding a workaround to a FAQ page doesn't in any way constitute implementing
the requested enhancement.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |WONTFIX



OK, then close as wontfix. It could also be invalid. Makes no difference.

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