src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java
changeset 50213 3085969bdf91
parent 49280 c2a3a2aa2475
child 50384 4d03087dd257
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Tue May 22 14:54:55 2018 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Tue May 22 13:37:05 2018 +0100
@@ -32,6 +32,7 @@
 import com.sun.tools.javac.code.Scope.WriteableScope;
 import com.sun.tools.javac.jvm.*;
 import com.sun.tools.javac.main.Option.PkgInfo;
+import com.sun.tools.javac.resources.CompilerProperties.Fragments;
 import com.sun.tools.javac.tree.*;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
@@ -721,14 +722,14 @@
 
         @Override
         public void visitMethodDef(JCMethodDecl that) {
-            chk.checkConflicts(that.pos(), that.sym, currentClass);
+            checkConflicts(that.pos(), that.sym, currentClass);
             super.visitMethodDef(that);
         }
 
         @Override
         public void visitVarDef(JCVariableDecl that) {
             if (that.sym.owner.kind == TYP) {
-                chk.checkConflicts(that.pos(), that.sym, currentClass);
+                checkConflicts(that.pos(), that.sym, currentClass);
             }
             super.visitVarDef(that);
         }
@@ -744,6 +745,30 @@
                 currentClass = prevCurrentClass;
             }
         }
+
+        void checkConflicts(DiagnosticPosition pos, Symbol sym, TypeSymbol c) {
+            for (Type ct = c.type; ct != Type.noType ; ct = types.supertype(ct)) {
+                for (Symbol sym2 : ct.tsym.members().getSymbolsByName(sym.name, NON_RECURSIVE)) {
+                    // VM allows methods and variables with differing types
+                    if (sym.kind == sym2.kind &&
+                        types.isSameType(types.erasure(sym.type), types.erasure(sym2.type)) &&
+                        sym != sym2 &&
+                        (sym.flags() & Flags.SYNTHETIC) != (sym2.flags() & Flags.SYNTHETIC) &&
+                        (sym.flags() & BRIDGE) == 0 && (sym2.flags() & BRIDGE) == 0) {
+                        syntheticError(pos, (sym2.flags() & SYNTHETIC) == 0 ? sym2 : sym);
+                        return;
+                    }
+                }
+            }
+        }
+
+        /** Report a conflict between a user symbol and a synthetic symbol.
+         */
+        private void syntheticError(DiagnosticPosition pos, Symbol sym) {
+            if (!sym.type.isErroneous()) {
+                log.error(pos, Errors.CannotGenerateClass(sym.location(), Fragments.SyntheticNameConflict(sym, sym.location())));
+            }
+        }
     };
 
     /** Look up a synthetic name in a given scope.