Jump to page: 1 2
Thread overview
[Issue 10103] New: template mixin with property overloads
May 17, 2013
Sebastian Graf
May 18, 2013
Kenji Hara
May 20, 2013
Kenji Hara
Oct 24, 2013
Kenji Hara
May 17, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103

           Summary: template mixin with property overloads
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: SebastianGraf@t-online.de


--- Comment #0 from Sebastian Graf <SebastianGraf@t-online.de> 2013-05-17 02:31:31 PDT ---
If you mix in getters and setters in seperate template mixins, it fails to
compile on first property-like usage.
Strangely, you may use both overloads if you treat them like functions (e.g.
the first examples in main below).
I think this is related to http://d.puremagic.com/issues/show_bug.cgi?id=1686
and http://d.puremagic.com/issues/show_bug.cgi?id=9235.

Offending code:

mixin template Getter() {
    @property auto x() { return _x; }
}

mixin template Setter() {
    @property void x(int x) { _x = x; }
}

struct Foo {
    int _x;
    mixin Getter!(); // definition order is irrelevant
    mixin Setter!();
}

void main() {
    auto f = Foo(4);
    auto x1 = f.x(); //fine
    f.x(2); // fine
    auto x2 = f.x; // Error: expression has no value
    f.x = 3; // Error: f.x is not an lvalue
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-05-17 22:10:31 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2047

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103



--- Comment #2 from github-bugzilla@puremagic.com 2013-05-20 09:13:01 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e892946b376b8365bc6cefd896e5e3e6a1219b16 fix Issue 10103 - template mixin with property overloads

https://github.com/D-Programming-Language/dmd/commit/fa4a52c8e832f43081349332ea3d274d976c54ca Merge pull request #2047 from 9rnsr/fix10103

Issue 10103 - template mixin with property overloads

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 20, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103



--- Comment #3 from github-bugzilla@puremagic.com 2013-05-29 18:25:59 PDT ---
Commit pushed to 2.063 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/76d09dfa5ef28176f666aa6f50038ed6a48b830b Fix 2.063 branch breaking

Bug10103 is not yet fixed in 2.063 branch.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103



--- Comment #4 from github-bugzilla@puremagic.com 2013-06-01 16:02:28 PDT ---
Commit pushed to 2.063 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/76d09dfa5ef28176f666aa6f50038ed6a48b830b Fix 2.063 branch breaking

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103



--- Comment #5 from Joseph Rushton Wakeling <joseph.wakeling@webdrake.net> 2013-10-23 23:39:05 PDT ---
Created an attachment (id=1281)
Alternative example of problem

The problem does not appear to be resolved in all cases.  See attached code, where a class takes _one_ of the implementations (getter _or_ setter) via a mixin, and the other is local.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103



--- Comment #6 from Joseph Rushton Wakeling <joseph.wakeling@webdrake.net> 2013-10-23 23:40:30 PDT ---
Created an attachment (id=1282)
Second example of bug still in existence

This second example has the _getter_ obtained via mixin, while the setter is in the class itself.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103


Joseph Rushton Wakeling <joseph.wakeling@webdrake.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |joseph.wakeling@webdrake.ne
                   |                            |t
         Resolution|FIXED                       |


--- Comment #7 from Joseph Rushton Wakeling <joseph.wakeling@webdrake.net> 2013-10-23 23:42:49 PDT ---
The current fix does not cover all possible cases.  The two recently-attached examples show cases where, of a getter/setter property pair, a class implements one of them locally and obtains the other via a mixin.  In both cases errors result:

    $ rdmd mixproperty.d
    mixproperty.d(30): Error: a.foo is not an lvalue

    $ rdmd mixproperty2.d
    mixproperty2.d(31): Error: function mixproperty2.A.foo (const(int) f) is
not callable using argument types ()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10103


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #8 from Kenji Hara <k.hara.pg@gmail.com> 2013-10-24 00:37:15 PDT ---
(In reply to comment #7)
> The current fix does not cover all possible cases.  The two recently-attached examples show cases where, of a getter/setter property pair, a class implements one of them locally and obtains the other via a mixin.  In both cases errors result:
> 
>     $ rdmd mixproperty.d
>     mixproperty.d(30): Error: a.foo is not an lvalue
> 
>     $ rdmd mixproperty2.d
>     mixproperty2.d(31): Error: function mixproperty2.A.foo (const(int) f) is
> not callable using argument types ()

No. The two cases does not work as you expected. **It's by design**.

mixin template B()
{
    void foo(int n) {}
}
class C
{
    void foo() {}

    // Mixed-in symbol foo(int) won't be automatically merged with foo().
    // In other words, C.foo() hides C.B!().foo(int) normally.
    mixin B;
}
void main()
{
    auto c = new C;
    c.foo();    // OK
    c.foo(1);   // NG, foo() is not callable using argument types (int)
}

If you want to make workable both c.foo() and c.foo(1), you need to change the
mixin declaration as follows.

class C
{
     ...
    mixin B x;
    alias foo = x.foo; // merge foo(int) in the overload set 'C.foo'
}
void main()
{
    auto c = new C;
    c.foo();    // OK
    c.foo(1);   // OK
}

I know that currently D does not have a feature to do it automatically. If you want to do it, you could design a language enhancement to resolve the issue.

Change back the issue status.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2