www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2810] New: ICE on auto function

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

           Summary: ICE on auto function
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: maxmo pochta.ru


---
auto a() { return 0; }
static assert(typeof(a).stringof);
---
Assertion failure: 'global.errors' on line 3845 in file 'mtype.c'
workaround: replace auto with int. --
Apr 06 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2810


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-valid-code           |rejects-valid
            Summary|ICE(mtype.c) on auto        |Cannot forward reference an
                   |function                    |auto function





The ICE was fixed in DMD2.031. Now it's just a rejects-valid.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 09 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2810


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
            Summary|Cannot forward reference an |Nonsensical forward
                   |auto function               |reference error - stringof
                   |                            |an auto function





You forgot to post the error messages.

1.046:
bz2810.d(1): no identifier for declarator a
bz2810.d(1): semicolon expected, not '{'
bz2810.d(1): Declaration expected, not '{'
bz2810.d(1): unrecognized declaration

2.031:
bz2810.d(2): Error: forward reference to a
bz2810.d(2): Error: forward reference to inferred return type of function call
(())()

(Windows)

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


Sobirari Muhomori <maxmo pochta.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Nonsensical forward         |Forward reference to an
                   |reference error - stringof  |auto function
                   |an auto function            |



---
Seems like this is a general forward reference bug, not specific to stringof.
----
void fun()
{
    gun(); //Error: forward reference to gun
}
auto gun()
{
    return 1;
}
----

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


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec



But there is no forward reference in the original testcase.  I think what
you've just described is a completely separate bug.

BTW I've just checked the spec (both D1 and D2), and it appears that functions
with auto return type aren't meant to work, so maybe this technically isn't
rejects-valid after all.

Decl:
        StorageClasses Decl
        BasicType Declarators ;
        BasicType Declarator FunctionBody
    AutoDeclaration

AutoDeclaration:
    StorageClasses Identifier = AssignExpression ;

But this seems an arbitrary restriction, given that you can create autotype
functions using literals.

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




---
A completely separate bug is actually what you described :) Auto functions are
obviously supported, I'm not sure if it's still valid to treat the auto keyword
as a storage class, if I'm not mistaken long ago it was meant to behave
differently.

The forward reference bugs are deeper than you think. The term "forward
reference" was taken from C world, the fact is compiler does things in an
order, and when at a certain step you need a result of a subsequent step, you
get into trouble. In C this situation happened for forward references in
lexical sense, because C compiler does things in lexical order. While D
compiler can first parse function signatures and then - function bodies, this
trick doesn't work for auto functions because their signatures can't be
resolved without compilation of the body, so their return types can be
accessible only at the end of semantic analysis. D compiler doesn't have
lexical forward reference bugs (except for the case of mixin) when you get
"undefined identifier" errors, but the compilation order is still here.

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


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |r.sagitario gmx.de



PDT ---
I just stumbled over this issue, too. What needs to done is to infer the return
type of the function (calling semantic3 on the function at a rather early stage
of compilation). Here's the patch:

Index: expression.c
===================================================================
--- expression.c    (revision 483)
+++ expression.c    (working copy)
   -2448,6 +2448,9   

         if (!f->originalType && f->scope)       // semantic not yet run
             f->semantic(f->scope);
+        // if inferring return type, sematic3 needs to be run
+        if(f->inferRetType && f->type && !f->type->nextOf())
+            f->semantic3(f->scope);
         if (!f->type->deco)
         {
             error("forward reference to %s", toChars());

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


Rainer Schuetze <r.sagitario gmx.de> changed:

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



PDT ---
*** Issue 4186 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: -------
May 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2810


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



06:32:44 PDT ---
I just hit this issue too.

I think the ultimate test for this should be:

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

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

Is this possible?  It may be too complex, even though the above should be
possible.

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


Witold Baryluk <baryluk smp.if.uj.edu.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |baryluk smp.if.uj.edu.pl



12:46:04 PST ---
Hi,

I also have similar problem, but involving two modules. Minimal test case (it
also appears when functions are templates, or returns templated classes, or int
type is changed to other type):

/*****************************/
module m2;

auto f(int x) {
   return x;
}

auto g(int x) {
   return f(x);
}
/*****************************/


/*****************************/
module m1;

import m2 : g;

void main() {
   g(5);
}
/*****************************/

It currently depend on the order of files given to the compiler.


m1.d(6): Error: forward reference to g





m1.d(6): Error: forward reference to g



As one can see there is actually NO forward references here. So I think it is
simpler than co-recursive version of Steven. Bug disappears when function f and
g, are moved to module m1. Or when function g have explicit return type.

It maybe also related to the bug involving order of files on command line to
the compiler.

Thanks.

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




Hit by the same bug, the reduced code:

int main() {
    return foo();
}
auto foo() {
    return 0;
}

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


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com



13:25:36 PST ---
Occurs also when using with typeof:

auto fun() { return 1; }
int gun(typeof(fun()) x) { return 2 + x; }

void main()
{
    gun(3);
}

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



21:49:06 PST ---
https://github.com/D-Programming-Language/dmd/commit/79d77f2bdf1c7f121afda1a8e2647fa4ab64f217

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




*** Issue 4075 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: -------
Feb 12 2011