Mixin template overloads not working

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 7 13:28:59 UTC 2021


On 12/7/21 7:43 AM, Rumbu wrote:
> On Friday, 3 December 2021 at 10:57:34 UTC, Stanislav Blinov wrote:
>> On Friday, 3 December 2021 at 10:42:37 UTC, Rumbu wrote:
>>
>>> Bug or feature? Is there any workaround?
>>
>> The error message explains what to do :)
>>
>>> Error: class `mixinover.AnotherVisitor` use of 
>>> `mixinover.Visitor.visit(S s)` is hidden by `AnotherVisitor`; use 
>>> `alias visit = Visitor.visit;` to introduce base class overload set
> 
> Yes, I know, but in fact the compiler wrongly assumes that visit(A) is 
> hiding visit(S). visit(A) is just an overload, it has a different 
> signature than visit(S), theoretically the compiler must mangle it using 
> a different name.

It doesn't have to do with mangling. It has to do with implicit conversions.

A more classic example would be:

```d
class A
{
    void foo(long i) {}
    void foo(int i) {}
}

class B : A
{
    override void foo(long i) {}
}
```

This hides A.foo(int), because B.foo(int) will call the long overload 
instead, when you might expect it to call the base class int overload.

But I agree with you that this seems like a bug -- the anti-hidden 
overload error is supposed to complain when you have an implicitly 
convertible parameter. In this case, you aren't hiding visit(S) because 
visit(A) would not accept an S.

The spec's explanation is pretty poor (and has invalid demo code to boot).

-Steve


More information about the Digitalmars-d-learn mailing list