1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Sun Nov 14 07:16:46 2010 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Nov 15 13:50:53 2010 +0000 1.3 @@ -1510,14 +1510,7 @@ 1.4 Type t1, 1.5 Type t2, 1.6 Type site) { 1.7 - Symbol sym = firstIncompatibility(t1, t2, site); 1.8 - if (sym != null) { 1.9 - log.error(pos, "types.incompatible.diff.ret", 1.10 - t1, t2, sym.name + 1.11 - "(" + types.memberType(t2, sym).getParameterTypes() + ")"); 1.12 - return false; 1.13 - } 1.14 - return true; 1.15 + return firstIncompatibility(pos, t1, t2, site) == null; 1.16 } 1.17 1.18 /** Return the first method which is defined with same args 1.19 @@ -1528,7 +1521,7 @@ 1.20 * @param site The most derived type. 1.21 * @returns symbol from t2 that conflicts with one in t1. 1.22 */ 1.23 - private Symbol firstIncompatibility(Type t1, Type t2, Type site) { 1.24 + private Symbol firstIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) { 1.25 Map<TypeSymbol,Type> interfaces1 = new HashMap<TypeSymbol,Type>(); 1.26 closure(t1, interfaces1); 1.27 Map<TypeSymbol,Type> interfaces2; 1.28 @@ -1539,7 +1532,7 @@ 1.29 1.30 for (Type t3 : interfaces1.values()) { 1.31 for (Type t4 : interfaces2.values()) { 1.32 - Symbol s = firstDirectIncompatibility(t3, t4, site); 1.33 + Symbol s = firstDirectIncompatibility(pos, t3, t4, site); 1.34 if (s != null) return s; 1.35 } 1.36 } 1.37 @@ -1568,7 +1561,7 @@ 1.38 } 1.39 1.40 /** Return the first method in t2 that conflicts with a method from t1. */ 1.41 - private Symbol firstDirectIncompatibility(Type t1, Type t2, Type site) { 1.42 + private Symbol firstDirectIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) { 1.43 for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) { 1.44 Symbol s1 = e1.sym; 1.45 Type st1 = null; 1.46 @@ -1592,7 +1585,18 @@ 1.47 (types.covariantReturnType(rt1, rt2, Warner.noWarnings) || 1.48 types.covariantReturnType(rt2, rt1, Warner.noWarnings)) || 1.49 checkCommonOverriderIn(s1,s2,site); 1.50 - if (!compat) return s2; 1.51 + if (!compat) { 1.52 + log.error(pos, "types.incompatible.diff.ret", 1.53 + t1, t2, s2.name + 1.54 + "(" + types.memberType(t2, s2).getParameterTypes() + ")"); 1.55 + return s2; 1.56 + } 1.57 + } else if (!checkNameClash((ClassSymbol)site.tsym, s1, s2)) { 1.58 + log.error(pos, 1.59 + "name.clash.same.erasure.no.override", 1.60 + s1, s1.location(), 1.61 + s2, s2.location()); 1.62 + return s2; 1.63 } 1.64 } 1.65 } 1.66 @@ -1644,32 +1648,52 @@ 1.67 log.error(tree.pos(), "enum.no.finalize"); 1.68 return; 1.69 } 1.70 - for (Type t = types.supertype(origin.type); t.tag == CLASS; 1.71 + for (Type t = origin.type; t.tag == CLASS; 1.72 t = types.supertype(t)) { 1.73 - TypeSymbol c = t.tsym; 1.74 - Scope.Entry e = c.members().lookup(m.name); 1.75 - while (e.scope != null) { 1.76 - if (m.overrides(e.sym, origin, types, false)) 1.77 - checkOverride(tree, m, (MethodSymbol)e.sym, origin); 1.78 - else if (e.sym.kind == MTH && 1.79 - e.sym.isInheritedIn(origin, types) && 1.80 - (e.sym.flags() & SYNTHETIC) == 0 && 1.81 - !m.isConstructor()) { 1.82 - Type er1 = m.erasure(types); 1.83 - Type er2 = e.sym.erasure(types); 1.84 - if (types.isSameTypes(er1.getParameterTypes(), 1.85 - er2.getParameterTypes())) { 1.86 - log.error(TreeInfo.diagnosticPositionFor(m, tree), 1.87 - "name.clash.same.erasure.no.override", 1.88 - m, m.location(), 1.89 - e.sym, e.sym.location()); 1.90 - } 1.91 - } 1.92 - e = e.next(); 1.93 + if (t != origin.type) { 1.94 + checkOverride(tree, t, origin, m); 1.95 + } 1.96 + for (Type t2 : types.interfaces(t)) { 1.97 + checkOverride(tree, t2, origin, m); 1.98 } 1.99 } 1.100 } 1.101 1.102 + void checkOverride(JCTree tree, Type site, ClassSymbol origin, MethodSymbol m) { 1.103 + TypeSymbol c = site.tsym; 1.104 + Scope.Entry e = c.members().lookup(m.name); 1.105 + while (e.scope != null) { 1.106 + if (m.overrides(e.sym, origin, types, false)) { 1.107 + if ((e.sym.flags() & ABSTRACT) == 0) { 1.108 + checkOverride(tree, m, (MethodSymbol)e.sym, origin); 1.109 + } 1.110 + } 1.111 + else if (!checkNameClash(origin, e.sym, m)) { 1.112 + log.error(tree, 1.113 + "name.clash.same.erasure.no.override", 1.114 + m, m.location(), 1.115 + e.sym, e.sym.location()); 1.116 + } 1.117 + e = e.next(); 1.118 + } 1.119 + } 1.120 + 1.121 + private boolean checkNameClash(ClassSymbol origin, Symbol s1, Symbol s2) { 1.122 + if (s1.kind == MTH && 1.123 + s1.isInheritedIn(origin, types) && 1.124 + (s1.flags() & SYNTHETIC) == 0 && 1.125 + !s2.isConstructor()) { 1.126 + Type er1 = s2.erasure(types); 1.127 + Type er2 = s1.erasure(types); 1.128 + if (types.isSameTypes(er1.getParameterTypes(), 1.129 + er2.getParameterTypes())) { 1.130 + return false; 1.131 + } 1.132 + } 1.133 + return true; 1.134 + } 1.135 + 1.136 + 1.137 /** Check that all abstract members of given class have definitions. 1.138 * @param pos Position to be used for error reporting. 1.139 * @param c The class.