D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8109 - typeof(function) within functions
Summary: typeof(function) within functions
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-16 01:22 UTC by Manu
Modified: 2024-12-13 17:59 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2012-05-16 01:22:45 UTC
There are some special typeof() implementations, typeof(this), typeof(super), etc, which may be used within the scope of a class to query these important details.

I'm frequently finding myself needing something like typeof(function), which would be valid within the scope of any function/method and produce its type.
I'm frequently finding myself needing to use mixins within a function which need to know information about the functions arguments so that it can generate code that references them.

For instance, very useful when creating pass-through/proxy functions, but I have some other uses too.
Comment 1 Nicholas Wilson 2019-06-10 09:13:05 UTC
So, typeof(this) and typeof(super) are just regular expression typeofs, typeof(return) is special because it needs deferred analysis when the return type is auto. 

This would effectively be just as special, if not more so. Do you still need this?
Comment 2 Manu 2019-06-10 09:18:34 UTC
I have needed this many times, and I think it's an obvious hole, especially in contrast to the presence of all the others.
Comment 3 basile-z 2019-06-10 13:08:13 UTC
What's needed is not a special typeof(function), but more a new symbol that represents the function we're in and that would work with typeof(). In addition it would be nice to have a special symbol that would represent the tuple of parameters.

using metaprog and __FUNCTION__ is known to work only when the current func has no overload.
Comment 4 Manu 2020-03-21 10:36:58 UTC
Yeah good point.
__FUNCTION__ really should have been that symbol you describe, then you could use __FUNCTION__.stringof or mangleof, or typeof(), etc...

Maybe introduce __function__ which is the symbol?
Comment 5 Dlang Bot 2020-08-09 10:27:05 UTC
@NilsLankila created dlang/dmd pull request #11538 "add `__traits(getCurrentFunction)`" mentioning this issue:

- add `__traits(getCurrentFunction)`
  
  - fix issue 8109
  - fix issue 9306
  
  This new traits is a shortcut allowing to call the function we
  are in without using `mixin` and `__FUNCTION__` tricks.

https://github.com/dlang/dmd/pull/11538
Comment 6 dlangBugzillaToGithub 2024-12-13 17:59:57 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18440

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB