[Issue 9551] New: template this parameter not recognized in constructors
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 20 07:36:58 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9551
Summary: template this parameter not recognized in constructors
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: gor.f.gyolchanyan at gmail.com
--- Comment #0 from Gor Gyolchanyan <gor.f.gyolchanyan at gmail.com> 2013-02-20 07:36:56 PST ---
The template this parameter, which works fine for normal methods:
class Base
{
string label;
this(string label_)
{
label = label_;
}
string toString(this This_)()
{
return This_.stringof ~ "(`" ~ label ~ "`)";
}
}
class Derived: Base
{
this()
{
super("Hello, world!");
}
}
unittest
{
Derived d = new Derived();
assert(d.toString() == "Derived(`Hello, world!`)");
}
doesn't work for constructors:
class Base
{
this(this This_)()
{
// Build a dispatch table using __traits(allMethods, This_)
}
void opCall(Payload_)(Payload_ payload_)
{
// Dynamically dispatch payload_ using the previously built
dispatch table.
}
}
class Derived: Base
{
// implicitly generated constructor will call the Base.this() and
implicitly give it the static type of Derived.
}
unittest
{
Base b = new Derived;
b(); // 100% transparent dynamic dispatch
}
Because of the following compile-time errors:
C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: found 'This_' when
expecting ')'
C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: semicolon expected
following function declaration
C:\Users\g.gyolchanyan\Desktop\test.d(3): Error: Declaration expected, not
')'
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list