D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15899 - Tuple.toString not recognized as a function with isSomeFunction
Summary: Tuple.toString not recognized as a function with isSomeFunction
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-08 20:08 UTC by Edwin van Leeuwen
Modified: 2016-04-11 08:21 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 Edwin van Leeuwen 2016-04-08 20:08:40 UTC
According to the documentation Tuple.toString should be a function, but is not recognized as such. The assert below fails:

void main()
{
    import std.traits : isSomeFunction;
    import std.typecons : Tuple;
    static assert(isSomeFunction!(Tuple!(int)(0).toString));
}
Comment 1 ag0aep6g 2016-04-08 23:20:48 UTC
std.typecons.Tuple.toString is not a function. It's a template. And the documentation says so [1]. So I think it's expected that isSomeFunction [2] returns false, as it's only supposed to accept functions, function pointers, and delegates.

I'm not sure why toString is a template, though. It's wrapped twice in zero-parameters templates, with no comment as to why. There may have been bugs or language limitations in the past that made this necessary. But now, Tuple being a template should be enough to trigger attribute inference for its methods, and templates and non-templates should be able to coexist in an overload set.

So it may be possible to just remove the `template toString()` and the extra empty parentheses from `string toString()()`. Then isSomeFunction would return true for Tuple.toString.


[1] http://dlang.org/phobos/std_typecons.html#.Tuple.toString
[2] http://dlang.org/phobos/std_traits.html#isSomeFunction
Comment 2 Edwin van Leeuwen 2016-04-11 08:15:07 UTC
That makes sense, thanks for the explanation.

Might be useful to add an isField attribute to traits. Previously I assumed that if something !isSomeFunction it would be a field, but that does not seem to be the case. Now changed that assumption to also ignore templates.