www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5288] New: auto return: forward ref error when using it with recursive functions

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

           Summary: auto return: forward ref error when using it with
                    recursive functions
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: nfxjfg gmail.com


--- Comment #0 from nfxjfg gmail.com 2010-11-29 03:21:53 PST ---
auto x(int z) {
    if (z == 1) {
        return x(z);  //line 3
    } else {
        return z;     //line 5
    }
}

z.d(3): Error: forward reference to x
z.d(5): Error: mismatched function return type inference of int and _error_

It works when you switch line 3 and 5.

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


nfxjfg gmail.com changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5288


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |braddr puremagic.com
         Resolution|WONTFIX                     |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 06 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5288


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #1 from Walter Bright <bugzilla digitalmars.com> 2011-04-03
22:12:01 PDT ---
This one is a little hard to fix, because the semantic analysis for function
bodies goes statement by statement in a forward manner.

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


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2011-04-04 11:54:27 PDT ---
(In reply to comment #1)
 This one is a little hard to fix, because the semantic analysis for function
 bodies goes statement by statement in a forward manner.
This is a nice bug report, and to solve this kind of code the D compiler probably needs a little more powerful type inference. If you are able to do this improvement with a reasonable amount of work and code, then it's OK. Otherwise an option it to mark this with WONTFIX to keep the D compiler simpler. A better type inferencer may require more compilation time and a bigger compiler. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 04 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5288


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|Other                       |All
         OS/Version|Linux                       |All


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-11-25 11:12:06 PST ---
There is mutually recursive call as a slightly more complex case.

From http://d.puremagic.com/issues/show_bug.cgi?id=2810#c8

auto foo()
{
    bar();
    return 1;
}

auto bar()
{
    foo();
    return 1;
}

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



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2011-12-03 06:06:08 PST ---
*** Issue 7059 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 03 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5288


Maksim Zholudev <maximzms gmail.com> changed:

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


--- Comment #5 from Maksim Zholudev <maximzms gmail.com> 2013-03-04 08:57:00
PST ---
Now this doesn't work even if lines 3 and 5 go in reverse order:
--------------------
auto x(int z) {
    if (z == 1) {
        return z;
    } else {
        return x(z);
    }
}
void main() {}
--------------------
test.d(6): Error: forward reference to x
--------------------

DMD from Git head:
https://github.com/D-Programming-Language/dmd/commit/13b3bdbf3819fec810ebfb077957510612dfa815

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 04 2013