D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21058 - __traits(getOverloads) forgets "this" with third argument or if first overload is a template
Summary: __traits(getOverloads) forgets "this" with third argument or if first overloa...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-07-19 16:17 UTC by Richard Manthorpe
Modified: 2020-07-27 10:55 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard Manthorpe 2020-07-19 16:17:48 UTC
struct A {
    int foo(string s) { return 0; }
}

static assert(__traits(getOverloads, A.init, "foo")[0]("hi") == 0); // works
static assert(__traits(getOverloads, A.init, "foo", true)[0]("hi") == 0); // Error: need this for foo of type int(string s)

struct B {
    int foo()(int i) { return 1; }
    int foo(string s) { return 0; }
}

static assert(__traits(getOverloads, B.init, "foo")[0]("hi") == 0); // Error: need this for foo of type int(string s)
static assert(__traits(getOverloads, B.init, "foo", true)[0]("hi") == 0); // Error: need this for foo of type int(string s)
static assert(__traits(getOverloads, B.init, "foo", true)[1](7) == 1); // Error: need this for foo of type pure nothrow @nogc @safe int(int i)

struct C {
    static int foo()(int i) { return 1; }
    int foo(string s) { return 0; }
}

static assert(__traits(getOverloads, C.init, "foo")[0]("hi") == 0); // Error: need this for foo of type int(string s)
static assert(__traits(getOverloads, C.init, "foo", true)[0]("hi") == 0); // Error: need this for foo of type int(string s)
static assert(__traits(getOverloads, C, "foo", true)[1](7) == 1); // works
Comment 1 Richard Manthorpe 2020-07-19 19:53:57 UTC
Ignore the third assert for struct B, that's kind of unrelated, more similar to https://issues.dlang.org/show_bug.cgi?id=18969
Comment 2 Dlang Bot 2020-07-19 19:58:07 UTC
@rmanthorpe created dlang/dmd pull request #11432 "Fix Issue 21058 - __traits(getOverloads) forgets "this" with third ar…" fixing this issue:

- Fix Issue 21058 - __traits(getOverloads) forgets "this" with third argument or if first overload is a template

https://github.com/dlang/dmd/pull/11432
Comment 3 Dlang Bot 2020-07-27 10:55:57 UTC
dlang/dmd pull request #11432 "Fix Issue 21058 - __traits(getOverloads) forgets "this" with third ar…" was merged into master:

- 5d78bf038f3848898f1f184141ab2349025ecaba by Richard Manthorpe:
  Fix Issue 21058 - __traits(getOverloads) forgets "this" with third argument or if first overload is a template
  
  When the target of `getOverloads` is a `dotTemplateDeclaration` we weren't
  propagating the context to the overloads. Similarly when including templates
  we weren't propagating the context even if we had one. This fixed both those
  problems.

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