Bug 17773 – this template parameter not working from derived class
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-08-22T16:38:21Z
Last change time
2018-03-09T18:53:10Z
Assigned to
No Owner
Creator
Martin Nowak
Comments
Comment #0 by code — 2017-08-22T16:38:21Z
cat > bug.d << CODE
class Base
{
this(size_t size)
{
}
size_t classSize(this This)()
{
pragma(msg, This);
return This.sizeof;
}
}
class Derived : Base
{
this()
{
super(classSize);
}
void foo()
{
classSize;
}
}
void test()
{
auto derived = new Derived;
auto size = derived.classSize;
}
CODE
dmd -c bug
----
bug.d(18): Error: constructor bug.Base.this (ulong size) is not callable using argument types (void)
bug.d(23): Error: template classSize(this This)() has no type
Derived
----
Seems like template this parameters are not correctly resolved/inferred when calling such methods from a derived instance.
Comment #1 by nick — 2018-03-09T18:46:16Z
Reduced with commented edit:
class Base
{
size_t classSize(this This)()
{
pragma(msg, This);
return This.sizeof;
}
}
class Derived : Base
{
void foo()
{
classSize(); // added ()
}
}
Error: template `templatethisparam.Base.classSize` cannot deduce function from argument types `!()()`, candidates are:
`templatethisparam.Base.classSize(this This)()`
Comment #2 by nick — 2018-03-09T18:53:10Z
Changing foo to use `this.classSize;` works.
*** This issue has been marked as a duplicate of issue 14484 ***