www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9551] New: template this parameter not recognized in constructors

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: gor.f.gyolchanyan gmail.com



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: -------
Feb 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551





 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
 ')'
As far as I see, it conflicts with postblit syntax `this(this)`. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551




08:15:30 PST ---


 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
 ')'
As far as I see, it conflicts with postblit syntax `this(this)`.
Yes, it definitely looks like it, but the existence of a type name after "this" in the template parameter list should disambiguate it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551







 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
 ')'
As far as I see, it conflicts with postblit syntax `this(this)`.
Yes, it definitely looks like it, but the existence of a type name after "this" in the template parameter list should disambiguate it.
But, it is not just only a parser problem. Constructor will be treated specially for object construction entry. And, unfortunately, language semantics between non-mutable object construction and qualified constructor is yet not defined well. The combination of TemplateThisParameter and constructor may touch similar *yet not defined semantics*. Therefore, I must say that this issue will not be fix soon. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551




08:31:09 PST ---




 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
 ')'
As far as I see, it conflicts with postblit syntax `this(this)`.
Yes, it definitely looks like it, but the existence of a type name after "this" in the template parameter list should disambiguate it.
But, it is not just only a parser problem. Constructor will be treated specially for object construction entry. And, unfortunately, language semantics between non-mutable object construction and qualified constructor is yet not defined well. The combination of TemplateThisParameter and constructor may touch similar *yet not defined semantics*. Therefore, I must say that this issue will not be fix soon.
This is extremely unfortunate, because this is the only way that I know of to implement transparent dynamic dispatch. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551





 
 This is extremely unfortunate, because this is the only way that I know of to
 implement transparent dynamic dispatch.
Couldn't you use helper function for the construction? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551




08:39:22 PST ---


 
 This is extremely unfortunate, because this is the only way that I know of to
 implement transparent dynamic dispatch.
Couldn't you use helper function for the construction?
Theoretically, I could, but it would require immense boilerplate when dealing with large class hierarchies, which is hard to enforce. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551







 
 This is extremely unfortunate, because this is the only way that I know of to
 implement transparent dynamic dispatch.
Couldn't you use helper function for the construction?
Theoretically, I could, but it would require immense boilerplate when dealing with large class hierarchies, which is hard to enforce.
I cannot imagine the 'immense boilerplate', but sorry it would need for a while. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com



09:01:14 PST ---


 As far as I see, it conflicts with postblit syntax `this(this)`.
Does it? postblit does not have the extra parentheses which is the signature of a template method. I'm asking out of ignorance. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9551






 
 As far as I see, it conflicts with postblit syntax `this(this)`.
Does it? postblit does not have the extra parentheses which is the signature of a template method. I'm asking out of ignorance.
I'm saying that _currently_ they are confused, and should be properly distinguished. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 20 2013