April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3543



--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> 2011-04-06 10:51:03 PDT ---
(In reply to comment #7)
> Interface hierarchies for a single-rooted DAG. In the DAG there are one or more common ancestors for any pair of nodes. The most specific one (farthest from the root) must be chosen. If there are two or more at the same depth that's an ambiguity error.

Interface hierarchies are not necessarily single rooted. They are multiply inherited.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3543



--- Comment #9 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-04-06 12:44:13 PDT ---
One can always connect an imaginary root to all rootless interfaces and apply the rule I mentioned. Let me add that "?:" is a cornerstone operator for a lot of traits and type deduction paraphernalia (e.g. std.traits.CommonType). I wouldn't insist in the matter if it weren't important beyond the convenience of "?:" itself.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3543



--- Comment #10 from Walter Bright <bugzilla@digitalmars.com> 2011-04-06 13:10:03 PDT ---
(In reply to comment #9)
> One can always connect an imaginary root to all rootless interfaces and apply the rule I mentioned. Let me add that "?:" is a cornerstone operator for a lot of traits and type deduction paraphernalia (e.g. std.traits.CommonType). I wouldn't insist in the matter if it weren't important beyond the convenience of "?:" itself.

I agree about the importance of the ?: algorithm. But I wonder if the compiler picking a common ancestor from a complex inheritance graph is really a good thing - it may prove surprising to the user. For example:

interface A : B,C,D,E
interface X : M,N,O,C

Is it really the right idea to pick C for the common type? I'm skeptical.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3543



--- Comment #11 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-04-06 13:26:45 PDT ---
(In reply to comment #10)
> (In reply to comment #9)
> > One can always connect an imaginary root to all rootless interfaces and apply the rule I mentioned. Let me add that "?:" is a cornerstone operator for a lot of traits and type deduction paraphernalia (e.g. std.traits.CommonType). I wouldn't insist in the matter if it weren't important beyond the convenience of "?:" itself.
> 
> I agree about the importance of the ?: algorithm. But I wonder if the compiler picking a common ancestor from a complex inheritance graph is really a good thing - it may prove surprising to the user. For example:
> 
> interface A : B,C,D,E
> interface X : M,N,O,C
> 
> Is it really the right idea to pick C for the common type? I'm skeptical.

Yes, in this case D is unequivocally the common type. A more interesting example is:

interface A {}
interface B {}
interface C : B {}
interface X : A, C {}
interface Y : A, C {}

By my suggested rule, C would be the common type as it's the most specific (most remote from a root). At the same time both A and C are equally distanced from X and Y so it's legitimate to ask on why A is not an equally good fit (and therefore an ambiguity).

A rule that would avoid that issue would be to count all common ancestors and find the one that is closest to both, i.e. shortest sum of steps from both interfaces. I thought of it but eliminated it because it can create rather subtle distinctions.

I agree the problem is not as clear cut as we'd like. OP?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3543



--- Comment #12 from bearophile_hugs@eml.cc 2011-04-06 13:44:34 PDT ---
Even modifying :? just for class instances will be a good improvement, this is not accepted by dmd 2.052:


class A {}
class B : A {}
class C : A {}
void main() {
    B b = new B;
    C c = new C;
    A[] array = [b, c];
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »