1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Aug 11 01:12:40 2009 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Aug 11 01:13:14 2009 +0100 1.3 @@ -596,34 +596,56 @@ 1.4 * Symbol manipulation utilities 1.5 *************************************************************************/ 1.6 1.7 - /** Report a conflict between a user symbol and a synthetic symbol. 1.8 - */ 1.9 - private void duplicateError(DiagnosticPosition pos, Symbol sym) { 1.10 - if (!sym.type.isErroneous()) { 1.11 - log.error(pos, "synthetic.name.conflict", sym, sym.location()); 1.12 - } 1.13 - } 1.14 - 1.15 /** Enter a synthetic symbol in a given scope, but complain if there was already one there. 1.16 * @param pos Position for error reporting. 1.17 * @param sym The symbol. 1.18 * @param s The scope. 1.19 */ 1.20 private void enterSynthetic(DiagnosticPosition pos, Symbol sym, Scope s) { 1.21 - if (sym.name != names.error && sym.name != names.empty) { 1.22 - for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) { 1.23 - if (sym != e.sym && sym.kind == e.sym.kind) { 1.24 - // VM allows methods and variables with differing types 1.25 - if ((sym.kind & (MTH|VAR)) != 0 && 1.26 - !types.erasure(sym.type).equals(types.erasure(e.sym.type))) 1.27 - continue; 1.28 - duplicateError(pos, e.sym); 1.29 - break; 1.30 - } 1.31 + s.enter(sym); 1.32 + } 1.33 + 1.34 + /** Check whether synthetic symbols generated during lowering conflict 1.35 + * with user-defined symbols. 1.36 + * 1.37 + * @param translatedTrees lowered class trees 1.38 + */ 1.39 + void checkConflicts(List<JCTree> translatedTrees) { 1.40 + for (JCTree t : translatedTrees) { 1.41 + t.accept(conflictsChecker); 1.42 + } 1.43 + } 1.44 + 1.45 + JCTree.Visitor conflictsChecker = new TreeScanner() { 1.46 + 1.47 + TypeSymbol currentClass; 1.48 + 1.49 + @Override 1.50 + public void visitMethodDef(JCMethodDecl that) { 1.51 + chk.checkConflicts(that.pos(), that.sym, currentClass); 1.52 + super.visitMethodDef(that); 1.53 + } 1.54 + 1.55 + @Override 1.56 + public void visitVarDef(JCVariableDecl that) { 1.57 + if (that.sym.owner.kind == TYP) { 1.58 + chk.checkConflicts(that.pos(), that.sym, currentClass); 1.59 + } 1.60 + super.visitVarDef(that); 1.61 + } 1.62 + 1.63 + @Override 1.64 + public void visitClassDef(JCClassDecl that) { 1.65 + TypeSymbol prevCurrentClass = currentClass; 1.66 + currentClass = that.sym; 1.67 + try { 1.68 + super.visitClassDef(that); 1.69 + } 1.70 + finally { 1.71 + currentClass = prevCurrentClass; 1.72 } 1.73 } 1.74 - s.enter(sym); 1.75 - } 1.76 + }; 1.77 1.78 /** Look up a synthetic name in a given scope. 1.79 * @param scope The scope. 1.80 @@ -3192,6 +3214,7 @@ 1.81 makeAccessible(l.head); 1.82 for (EnumMapping map : enumSwitchMap.values()) 1.83 map.translate(); 1.84 + checkConflicts(this.translated.toList()); 1.85 translated = this.translated; 1.86 } finally { 1.87 // note that recursive invocations of this method fail hard