[Issue 10103] template mixin with property overloads

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 24 00:37:17 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10103


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

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


--- Comment #8 from Kenji Hara <k.hara.pg at 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: -------


More information about the Digitalmars-d-bugs mailing list