Beta D 2.068.1-b2
Steven Schveighoffer via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Fri Sep 4 06:15:28 PDT 2015
On 9/4/15 8:14 AM, Steven Schveighoffer wrote:
> Why did this compile/pass tests then? I wasn't aware of this restriction.
>
> https://github.com/D-Programming-Language/phobos/pull/3572
OK, I dug into it further.
It seems that under some level of detection of whether a function that
could be called on the base is really called on the derived, then the
derived function is not allowed to mask the base function.
HOWEVER, if the call would result in an error instead, then the override
is totally fine, and calling the function on a base reference actually
calls the masked function. This seems incorrect, when you mask a
function, I would consider that to be hidden also.
So technically, the error is that the toString masking could be called
in the same way the base could be called (given the default parameter).
This sure seems arbitrary to me. I remember the whole thing about
function hijacking, but this hidden function "feature" doesn't make a
lot of sense. In one case, you can hide it, but still access it from the
base, in another, the compiler was rewriting the vtable to not allow you
to access it from the base, on what seems to be an arbitrary concern.
And that now is a compiler error.
I wonder how this will affect multiple alias this, since you could
potentially have a type that converts to two disjoint types, but
wouldn't be known to the compiler if a base and derived class accepted
the disjoint types.
-Steve
More information about the Digitalmars-d-announce
mailing list