Thread overview
[Issue 790] New: arbitrary lookahead for nested functions
Jan 03, 2007
d-bugmail
Jan 04, 2007
BCS
Jan 04, 2007
d-bugmail
Nov 26, 2010
nfxjfg@gmail.com
Sep 27, 2012
Don
Sep 29, 2012
Stewart Gordon
Nov 13, 2012
Don
January 03, 2007
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.


-- 

January 04, 2007
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.
-------------
January 04, 2007
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.


-- 

November 26, 2010
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: -------
November 26, 2010
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: -------
April 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=790



--- Comment #4 from github-bugzilla@puremagic.com 2012-04-14 22:37:53 PDT ---
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: -------
September 27, 2012
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


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2012-09-27 01:36:05 PDT ---
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: -------
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=790


Stewart Gordon <smjg@iname.com> changed:

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


--- Comment #6 from Stewart Gordon <smjg@iname.com> 2012-09-28 18:17:09 PDT ---
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: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=790


Don <clugdbug@yahoo.com.au> changed:

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


--- Comment #7 from Don <clugdbug@yahoo.com.au> 2012-11-12 23:52:06 PST ---
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: -------