langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
changeset 21025 9d4e765fe447
parent 21018 95d225149128
child 21041 99f5e5e97425
equal deleted inserted replaced
21024:e1efbecefefa 21025:9d4e765fe447
  2397      */
  2397      */
  2398     void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) {
  2398     void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) {
  2399          ClashFilter cf = new ClashFilter(site);
  2399          ClashFilter cf = new ClashFilter(site);
  2400         //for each method m1 that is overridden (directly or indirectly)
  2400         //for each method m1 that is overridden (directly or indirectly)
  2401         //by method 'sym' in 'site'...
  2401         //by method 'sym' in 'site'...
       
  2402 
       
  2403         List<MethodSymbol> potentiallyAmbiguousList = List.nil();
       
  2404         boolean overridesAny = false;
  2402         for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  2405         for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  2403              if (!sym.overrides(m1, site.tsym, types, false)) {
  2406             if (!sym.overrides(m1, site.tsym, types, false)) {
  2404                  checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)m1);
  2407                 if (m1 == sym) {
  2405                  continue;
  2408                     continue;
  2406              }
  2409                 }
  2407              //...check each method m2 that is a member of 'site'
  2410 
  2408              for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  2411                 if (!overridesAny) {
       
  2412                     potentiallyAmbiguousList = potentiallyAmbiguousList.prepend((MethodSymbol)m1);
       
  2413                 }
       
  2414                 continue;
       
  2415             }
       
  2416 
       
  2417             if (m1 != sym) {
       
  2418                 overridesAny = true;
       
  2419                 potentiallyAmbiguousList = List.nil();
       
  2420             }
       
  2421 
       
  2422             //...check each method m2 that is a member of 'site'
       
  2423             for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  2409                 if (m2 == m1) continue;
  2424                 if (m2 == m1) continue;
  2410                 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
  2425                 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
  2411                 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error
  2426                 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error
  2412                 if (!types.isSubSignature(sym.type, types.memberType(site, m2), allowStrictMethodClashCheck) &&
  2427                 if (!types.isSubSignature(sym.type, types.memberType(site, m2), allowStrictMethodClashCheck) &&
  2413                         types.hasSameArgs(m2.erasure(types), m1.erasure(types))) {
  2428                         types.hasSameArgs(m2.erasure(types), m1.erasure(types))) {
  2422                             m1, m1.location());
  2437                             m1, m1.location());
  2423                     return;
  2438                     return;
  2424                 }
  2439                 }
  2425             }
  2440             }
  2426         }
  2441         }
  2427     }
  2442 
  2428 
  2443         if (!overridesAny) {
  2429 
  2444             for (MethodSymbol m: potentiallyAmbiguousList) {
       
  2445                 checkPotentiallyAmbiguousOverloads(pos, site, sym, m);
       
  2446             }
       
  2447         }
       
  2448     }
  2430 
  2449 
  2431     /** Check that all static methods accessible from 'site' are
  2450     /** Check that all static methods accessible from 'site' are
  2432      *  mutually compatible (JLS 8.4.8).
  2451      *  mutually compatible (JLS 8.4.8).
  2433      *
  2452      *
  2434      *  @param pos  Position to be used for error reporting.
  2453      *  @param pos  Position to be used for error reporting.