Bug 20277 – Template this parameters are not respected in static context
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-10-07T11:48:45Z
Last change time
2022-09-14T13:26:32Z
Assigned to
No Owner
Creator
Max Samukha
Comments
Comment #0 by maxsamukha — 2019-10-07T11:48:45Z
class A {
void foo(this T)() {
}
static void bar(this T)() {
}
template baz(this T) {
static void baz() {
}
}
}
class B : A {
}
void main()
{
B b;
b.foo(); // ok
B.bar(); //fail
b.bar(); // fail
b.baz(); // ok
B.baz(); // fail
}
onlineapp.d(22): Error: template onlineapp.A.bar cannot deduce function from argument types !()(), candidates are:
onlineapp.d(5): bar(this T)()
onlineapp.d(23): Error: template onlineapp.A.bar cannot deduce function from argument types !()(), candidates are:
onlineapp.d(5): bar(this T)()
onlineapp.d(26): Error: template onlineapp.A.baz cannot deduce function from argument types !()(), candidates are:
onlineapp.d(8): baz(this T)()
run.dlang.io: https://run.dlang.io/is/Hme9vp
Accessing the static type of a class in the context of a base class is an extremely useful feature, and there is no reason to restrict it to just non-static functions, precluding valid use cases like factory function generation etc.
Comment #1 by maxsamukha — 2020-05-10T16:25:42Z
*** Issue 20816 has been marked as a duplicate of this issue. ***
Comment #2 by destructionator — 2020-05-10T17:00:19Z
in the duplicate i argue from the spec that this should work too
Comment #3 by nick — 2022-09-14T13:26:32Z
*** This issue has been marked as a duplicate of issue 10488 ***