276 private boolean notOverriddenIn(Type site, Symbol sym) { |
276 private boolean notOverriddenIn(Type site, Symbol sym) { |
277 if (sym.kind != MTH || sym.isConstructor() || sym.isStatic()) |
277 if (sym.kind != MTH || sym.isConstructor() || sym.isStatic()) |
278 return true; |
278 return true; |
279 else { |
279 else { |
280 Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true); |
280 Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true); |
281 return (s2 == null || s2 == sym || |
281 return (s2 == null || s2 == sym || sym.owner == s2.owner || |
282 s2.isPolymorphicSignatureGeneric() || |
282 s2.isPolymorphicSignatureGeneric() || |
283 !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym))); |
283 !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym))); |
284 } |
284 } |
285 } |
285 } |
286 //where |
286 //where |
710 boolean m2SignatureMoreSpecific = signatureMoreSpecific(env, site, m2, m1, allowBoxing, useVarargs); |
710 boolean m2SignatureMoreSpecific = signatureMoreSpecific(env, site, m2, m1, allowBoxing, useVarargs); |
711 if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) { |
711 if (m1SignatureMoreSpecific && m2SignatureMoreSpecific) { |
712 Type mt1 = types.memberType(site, m1); |
712 Type mt1 = types.memberType(site, m1); |
713 Type mt2 = types.memberType(site, m2); |
713 Type mt2 = types.memberType(site, m2); |
714 if (!types.overrideEquivalent(mt1, mt2)) |
714 if (!types.overrideEquivalent(mt1, mt2)) |
715 return new AmbiguityError(m1, m2); |
715 return ambiguityError(m1, m2); |
|
716 |
716 // same signature; select (a) the non-bridge method, or |
717 // same signature; select (a) the non-bridge method, or |
717 // (b) the one that overrides the other, or (c) the concrete |
718 // (b) the one that overrides the other, or (c) the concrete |
718 // one, or (d) merge both abstract signatures |
719 // one, or (d) merge both abstract signatures |
719 if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE)) { |
720 if ((m1.flags() & BRIDGE) != (m2.flags() & BRIDGE)) |
720 return ((m1.flags() & BRIDGE) != 0) ? m2 : m1; |
721 return ((m1.flags() & BRIDGE) != 0) ? m2 : m1; |
721 } |
722 |
722 // if one overrides or hides the other, use it |
723 // if one overrides or hides the other, use it |
723 TypeSymbol m1Owner = (TypeSymbol)m1.owner; |
724 TypeSymbol m1Owner = (TypeSymbol)m1.owner; |
724 TypeSymbol m2Owner = (TypeSymbol)m2.owner; |
725 TypeSymbol m2Owner = (TypeSymbol)m2.owner; |
725 if (types.asSuper(m1Owner.type, m2Owner) != null && |
726 if (types.asSuper(m1Owner.type, m2Owner) != null && |
726 ((m1.owner.flags_field & INTERFACE) == 0 || |
727 ((m1.owner.flags_field & INTERFACE) == 0 || |
736 boolean m2Abstract = (m2.flags() & ABSTRACT) != 0; |
737 boolean m2Abstract = (m2.flags() & ABSTRACT) != 0; |
737 if (m1Abstract && !m2Abstract) return m2; |
738 if (m1Abstract && !m2Abstract) return m2; |
738 if (m2Abstract && !m1Abstract) return m1; |
739 if (m2Abstract && !m1Abstract) return m1; |
739 // both abstract or both concrete |
740 // both abstract or both concrete |
740 if (!m1Abstract && !m2Abstract) |
741 if (!m1Abstract && !m2Abstract) |
741 return new AmbiguityError(m1, m2); |
742 return ambiguityError(m1, m2); |
742 // check that both signatures have the same erasure |
743 // check that both signatures have the same erasure |
743 if (!types.isSameTypes(m1.erasure(types).getParameterTypes(), |
744 if (!types.isSameTypes(m1.erasure(types).getParameterTypes(), |
744 m2.erasure(types).getParameterTypes())) |
745 m2.erasure(types).getParameterTypes())) |
745 return new AmbiguityError(m1, m2); |
746 return ambiguityError(m1, m2); |
746 // both abstract, neither overridden; merge throws clause and result type |
747 // both abstract, neither overridden; merge throws clause and result type |
747 Symbol mostSpecific; |
748 Symbol mostSpecific; |
748 Type result2 = mt2.getReturnType(); |
749 Type result2 = mt2.getReturnType(); |
749 if (mt2.tag == FORALL) |
750 if (mt2.tag == FORALL) |
750 result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars); |
751 result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars); |
751 if (types.isSubtype(mt1.getReturnType(), result2)) { |
752 if (types.isSubtype(mt1.getReturnType(), result2)) |
752 mostSpecific = m1; |
753 mostSpecific = m1; |
753 } else if (types.isSubtype(result2, mt1.getReturnType())) { |
754 else if (types.isSubtype(result2, mt1.getReturnType())) |
754 mostSpecific = m2; |
755 mostSpecific = m2; |
755 } else { |
756 else { |
756 // Theoretically, this can't happen, but it is possible |
757 // Theoretically, this can't happen, but it is possible |
757 // due to error recovery or mixing incompatible class files |
758 // due to error recovery or mixing incompatible class files |
758 return new AmbiguityError(m1, m2); |
759 return ambiguityError(m1, m2); |
759 } |
760 } |
760 MethodSymbol result = new MethodSymbol( |
761 MethodSymbol result = new MethodSymbol( |
761 mostSpecific.flags(), |
762 mostSpecific.flags(), |
762 mostSpecific.name, |
763 mostSpecific.name, |
763 null, |
764 null, |
775 mt2.getThrownTypes())); |
776 mt2.getThrownTypes())); |
776 return result; |
777 return result; |
777 } |
778 } |
778 if (m1SignatureMoreSpecific) return m1; |
779 if (m1SignatureMoreSpecific) return m1; |
779 if (m2SignatureMoreSpecific) return m2; |
780 if (m2SignatureMoreSpecific) return m2; |
780 return new AmbiguityError(m1, m2); |
781 return ambiguityError(m1, m2); |
781 case AMBIGUOUS: |
782 case AMBIGUOUS: |
782 AmbiguityError e = (AmbiguityError)m2; |
783 AmbiguityError e = (AmbiguityError)m2; |
783 Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs); |
784 Symbol err1 = mostSpecific(m1, e.sym, env, site, allowBoxing, useVarargs); |
784 Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs); |
785 Symbol err2 = mostSpecific(m1, e.sym2, env, site, allowBoxing, useVarargs); |
785 if (err1 == err2) return err1; |
786 if (err1 == err2) return err1; |
786 if (err1 == e.sym && err2 == e.sym2) return m2; |
787 if (err1 == e.sym && err2 == e.sym2) return m2; |
787 if (err1 instanceof AmbiguityError && |
788 if (err1 instanceof AmbiguityError && |
788 err2 instanceof AmbiguityError && |
789 err2 instanceof AmbiguityError && |
789 ((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym) |
790 ((AmbiguityError)err1).sym == ((AmbiguityError)err2).sym) |
790 return new AmbiguityError(m1, m2); |
791 return ambiguityError(m1, m2); |
791 else |
792 else |
792 return new AmbiguityError(err1, err2); |
793 return ambiguityError(err1, err2); |
793 default: |
794 default: |
794 throw new AssertionError(); |
795 throw new AssertionError(); |
795 } |
796 } |
796 } |
797 } |
797 //where |
798 //where |
840 MethodType mtype = msym.type.asMethodType(); |
841 MethodType mtype = msym.type.asMethodType(); |
841 mtype.argtypes = args.toList(); |
842 mtype.argtypes = args.toList(); |
842 return msym; |
843 return msym; |
843 } else { |
844 } else { |
844 return to; |
845 return to; |
|
846 } |
|
847 } |
|
848 //where |
|
849 Symbol ambiguityError(Symbol m1, Symbol m2) { |
|
850 if (((m1.flags() | m2.flags()) & CLASH) != 0) { |
|
851 return (m1.flags() & CLASH) == 0 ? m1 : m2; |
|
852 } else { |
|
853 return new AmbiguityError(m1, m2); |
845 } |
854 } |
846 } |
855 } |
847 |
856 |
848 /** Find best qualified method matching given name, type and value |
857 /** Find best qualified method matching given name, type and value |
849 * arguments. |
858 * arguments. |