www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7947] New: typeof on anonymous function literal returns void

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

           Summary: typeof on anonymous function literal returns void
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: james aatch.net



The following code:

  pragma(msg, typeof(x => x));

prints out void. Semi understandable, if unintuitive.

this also does

  test(alias fn, T)(T t)
  if(is(typeof(fn(t))))
  {
    pragma(msg, typeof(fn));
  }
  test!(x => x < 5)(10);

Which is more annoying. There should either be an error in this case

Also happens with expanded function(...){...} syntax, as long as the parameter
types are not specified.

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




A lambda expression that needs parameter type inference is internally
translated to template function.

  x => x
  // auto __lambda(T1)(T1 x){ return x; }

So this:

  pragma(msg, typeof(x => x));

is same as:

  pragma(msg, typeof(__lambda));
  // template itself has no type, then typeof(template) always returns void

And, long years, typeof(template) returns void.
Therefore, typeof(x => x) == void is current implementation design.

I don't know why typeof(template) returns void, but changing the behavior will
break some existing meta-programming codes.

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


bearophile_hugs eml.cc changed:

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





 And, long years, typeof(template) returns void.
 Therefore, typeof(x => x) == void is current implementation design.
 
 I don't know why typeof(template) returns void, but changing the behavior will
 break some existing meta-programming codes.
I think it's acceptable to break such meta-programming code. I think pragma(msg, typeof(tem)); should show something useful when tem is a template function (like the name of the template if it has a name, or a lambda template plus line number if it has no name). There are people working on an algorithm to automatically synthesize good names for anonymous functions, but probably it's overkill in D "Naming Anonymous JavaScript Functions": http://blog.getfirebug.com/2011/04/28/naming-anonymous-javascript-functions/ http://code.google.com/p/querypoint-debugging/downloads/detail?name=NamingJSFunctions.pdf -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7947


yebblies <yebblies gmail.com> changed:

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



There is another case where using void as the type of template lambdas causes
problems, (but of course I can't remember where).  It might be worth adding a
Ttemplate dummy type and just printing "template" here.

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