Bug 21058 – __traits(getOverloads) forgets "this" with third argument or if first overload is a template

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-19T16:17:48Z
Last change time
2020-07-27T10:55:57Z
Keywords
pull
Assigned to
No Owner
Creator
Richard Manthorpe

Comments

Comment #0 by rmanth — 2020-07-19T16:17:48Z
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 by rmanth — 2020-07-19T19:53:57Z
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 by dlang-bot — 2020-07-19T19:58:07Z
@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 by dlang-bot — 2020-07-27T10:55:57Z
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