This code compiled with 2.062:
class Foo
{
static void instance (this T) ()
{
}
}
void main ()
{
Foo.instance();
}
With 2.063 I get this error:
main.d(10): Error: template main.Foo.instance does not match any function template declaration. Candidates are:
main.d(3): main.Foo.instance(this T)()
main.d(10): Error: template main.Foo.instance(this T)() cannot deduce template function from argument types !()()
Comment #1 by k.hara.pg — 2013-06-27T20:50:38Z
That was "accepts-invalid" bug.
Even with 2.062, it didn't work properly.
class Foo
{
static void instance (this T) () {}
}
void main ()
{
import std.typetuple;
foreach (T; TypeTuple!(Foo, const Foo, immutable Foo))
{
pragma(msg, T);
T.instance(); // fail to compile with const and immutable
}
}
static member function does not have valid 'this' expression, so compiler cannot deduce TemplateThisParameter with IFTI.
Comment #2 by doob — 2013-06-28T01:29:36Z
I thought that the whole point was to use it when "this" wasn't normally allowed. Just like typeof(this) can be used outside instance methods.
Comment #3 by schuetzm — 2015-10-25T12:02:53Z
IMO the fact that `typeof(this)` is allowed in static methods is a compelling argument to allow this. It has interesting applications when combined with inheritance, see this forum post:
http://forum.dlang.org/post/[email protected]
Therefore I'm reopening this issue as an enhancement request.
Comment #4 by nick — 2018-02-01T13:41:05Z
*** Issue 17713 has been marked as a duplicate of this issue. ***
Comment #5 by nick — 2018-02-01T13:42:25Z
The above duplicate has a nice test case and also a comment that template this should be allowed anywhere inside a class, not just static function templates.
Comment #6 by nick — 2018-03-09T19:06:07Z
*** Issue 14191 has been marked as a duplicate of this issue. ***
Comment #7 by nick — 2022-09-14T13:26:32Z
*** Issue 20277 has been marked as a duplicate of this issue. ***
Comment #8 by dlang-bot — 2022-09-16T13:24:34Z
@ntrel created dlang/dmd pull request #14446 "Infer template this parameter when calling static method on instance" mentioning this issue:
- Infer template this parameter when calling static method on instance
Part of Issue 10488 - Allow template this parameter with static functions.
Note: `tthis` is only used in `doHeaderInstantiation` for template this
so assigning null when there's a static storage class is not needed for
anything else.
https://github.com/dlang/dmd/pull/14446
Comment #9 by dlang-bot — 2022-09-26T02:35:02Z
dlang/dmd pull request #14446 "Infer template this parameter when calling static method on instance" was merged into master:
- 0121a59283ab9eb20b8fff646f90df7bd3fbfe13 by Nick Treleaven:
Infer template this parameter when calling static method on instance
Part of Issue 10488 - Allow template this parameter with static functions.
https://github.com/dlang/dmd/pull/14446
Comment #10 by dlang-bot — 2022-09-27T14:46:41Z
@maxhaton updated dlang/dmd pull request #14482 "Fix Issue 23368 - Don't segfault on throwing null exception" mentioning this issue:
- Infer template this parameter when calling static method on instance (#14446)
* Infer template this parameter when calling static method on instance
Part of Issue 10488 - Allow template this parameter with static functions.
* Apply suggestions from code review
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis <[email protected]>
https://github.com/dlang/dmd/pull/14482
Comment #11 by robert.schadek — 2024-12-13T18:08:43Z