Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow template this parameter to work with static functions #18618

Open
dlangBugzillaToGithub opened this issue Jun 27, 2013 · 10 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

Jacob Carlborg (@jacob-carlborg) reported this on 2013-06-27T08:54:06Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=10488

CC List

  • Orvid King
  • Adam D. Ruppe
  • Max Samukha
  • Nick Treleaven (@ntrel)
  • Marc Schütz

Description

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 !()()
@dlangBugzillaToGithub
Copy link
Author

k.hara.pg commented on 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.

@dlangBugzillaToGithub
Copy link
Author

doob (@jacob-carlborg) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

schuetzm commented on 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/n0gl6m$1oms$1@digitalmars.com

Therefore I'm reopening this issue as an enhancement request.

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2018-02-01T13:41:05Z

*** Issue 17713 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2018-03-09T19:06:07Z

*** Issue 14191 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2022-09-14T13:26:32Z

*** Issue 20277 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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 <dkorpel@users.noreply.github.com>
  
  Co-authored-by: Dennis <dkorpel@users.noreply.github.com>

https://github.com/dlang/dmd/pull/14482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant