langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
changeset 42827 36468b5fa7f4
parent 42824 89b14017e8d6
child 42828 cce89649f958
equal deleted inserted replaced
42826:563b42fc70ba 42827:36468b5fa7f4
   879          * varargs element type of either the method invocation type signature (after inference completes)
   879          * varargs element type of either the method invocation type signature (after inference completes)
   880          * or the method declaration signature (before inference completes).
   880          * or the method declaration signature (before inference completes).
   881          */
   881          */
   882         private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) {
   882         private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) {
   883             if (inferenceContext.free(t)) {
   883             if (inferenceContext.free(t)) {
   884                 inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() {
   884                 inferenceContext.addFreeTypeListener(List.of(t),
   885                     @Override
   885                         solvedContext -> varargsAccessible(env, solvedContext.asInstType(t), solvedContext));
   886                     public void typesInferred(InferenceContext inferenceContext) {
       
   887                         varargsAccessible(env, inferenceContext.asInstType(t), inferenceContext);
       
   888                     }
       
   889                 });
       
   890             } else {
   886             } else {
   891                 if (!isAccessible(env, types.erasure(t))) {
   887                 if (!isAccessible(env, types.erasure(t))) {
   892                     Symbol location = env.enclClass.sym;
   888                     Symbol location = env.enclClass.sym;
   893                     reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location);
   889                     reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location);
   894                 }
   890                 }
  1849      * It's crucial that the scan is done lazily, as we don't want to accidentally
  1845      * It's crucial that the scan is done lazily, as we don't want to accidentally
  1850      * access more supertypes than strictly needed (as this could trigger completion
  1846      * access more supertypes than strictly needed (as this could trigger completion
  1851      * errors if some of the not-needed supertypes are missing/ill-formed).
  1847      * errors if some of the not-needed supertypes are missing/ill-formed).
  1852      */
  1848      */
  1853     Iterable<TypeSymbol> superclasses(final Type intype) {
  1849     Iterable<TypeSymbol> superclasses(final Type intype) {
  1854         return new Iterable<TypeSymbol>() {
  1850         return () -> new Iterator<TypeSymbol>() {
  1855             public Iterator<TypeSymbol> iterator() {
  1851 
  1856                 return new Iterator<TypeSymbol>() {
  1852             List<TypeSymbol> seen = List.nil();
  1857 
  1853             TypeSymbol currentSym = symbolFor(intype);
  1858                     List<TypeSymbol> seen = List.nil();
  1854             TypeSymbol prevSym = null;
  1859                     TypeSymbol currentSym = symbolFor(intype);
  1855 
  1860                     TypeSymbol prevSym = null;
  1856             public boolean hasNext() {
  1861 
  1857                 if (currentSym == syms.noSymbol) {
  1862                     public boolean hasNext() {
  1858                     currentSym = symbolFor(types.supertype(prevSym.type));
  1863                         if (currentSym == syms.noSymbol) {
  1859                 }
  1864                             currentSym = symbolFor(types.supertype(prevSym.type));
  1860                 return currentSym != null;
  1865                         }
  1861             }
  1866                         return currentSym != null;
  1862 
  1867                     }
  1863             public TypeSymbol next() {
  1868 
  1864                 prevSym = currentSym;
  1869                     public TypeSymbol next() {
  1865                 currentSym = syms.noSymbol;
  1870                         prevSym = currentSym;
  1866                 Assert.check(prevSym != null || prevSym != syms.noSymbol);
  1871                         currentSym = syms.noSymbol;
  1867                 return prevSym;
  1872                         Assert.check(prevSym != null || prevSym != syms.noSymbol);
  1868             }
  1873                         return prevSym;
  1869 
  1874                     }
  1870             public void remove() {
  1875 
  1871                 throw new UnsupportedOperationException();
  1876                     public void remove() {
  1872             }
  1877                         throw new UnsupportedOperationException();
  1873 
  1878                     }
  1874             TypeSymbol symbolFor(Type t) {
  1879 
  1875                 if (!t.hasTag(CLASS) &&
  1880                     TypeSymbol symbolFor(Type t) {
  1876                         !t.hasTag(TYPEVAR)) {
  1881                         if (!t.hasTag(CLASS) &&
  1877                     return null;
  1882                                 !t.hasTag(TYPEVAR)) {
  1878                 }
  1883                             return null;
  1879                 t = types.skipTypeVars(t, false);
  1884                         }
  1880                 if (seen.contains(t.tsym)) {
  1885                         t = types.skipTypeVars(t, false);
  1881                     //degenerate case in which we have a circular
  1886                         if (seen.contains(t.tsym)) {
  1882                     //class hierarchy - because of ill-formed classfiles
  1887                             //degenerate case in which we have a circular
  1883                     return null;
  1888                             //class hierarchy - because of ill-formed classfiles
  1884                 }
  1889                             return null;
  1885                 seen = seen.prepend(t.tsym);
  1890                         }
  1886                 return t.tsym;
  1891                         seen = seen.prepend(t.tsym);
       
  1892                         return t.tsym;
       
  1893                     }
       
  1894                 };
       
  1895             }
  1887             }
  1896         };
  1888         };
  1897     }
  1889     }
  1898 
  1890 
  1899     /** Find unqualified method matching given name, type and value arguments.
  1891     /** Find unqualified method matching given name, type and value arguments.