< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Print this page
*** 51,11 ***
  import com.sun.tools.javac.util.*;
  import com.sun.tools.javac.util.DefinedBy.Api;
  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType;
- import com.sun.tools.javac.util.JCDiagnostic.Warning;
  
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.EnumSet;
  import java.util.HashSet;
--- 51,10 ---

*** 63,11 ***
  import java.util.LinkedHashMap;
  import java.util.Map;
  import java.util.Set;
  import java.util.function.BiFunction;
  import java.util.function.BiPredicate;
- import java.util.function.Consumer;
  import java.util.function.Function;
  import java.util.function.Predicate;
  import java.util.function.UnaryOperator;
  import java.util.stream.Stream;
  import java.util.stream.StreamSupport;
--- 62,10 ---

*** 106,15 ***
--- 104,17 ---
      ModuleFinder moduleFinder;
      Types types;
      JCDiagnostic.Factory diags;
      public final boolean allowModules;
      public final boolean allowRecords;
+     public final boolean allowValueClasses;
      private final boolean compactMethodDiags;
      private final boolean allowLocalVariableTypeInference;
      private final boolean allowYieldStatement;
      final EnumSet<VerboseResolutionMode> verboseResolutionMode;
      final boolean dumpMethodReferenceSearchResults;
+     final boolean allowPrimitiveClasses;
  
      WriteableScope polymorphicSignatureScope;
  
      protected Resolve(Context context) {
          context.put(resolveKey, this);

*** 147,10 ***
--- 147,12 ---
          allowYieldStatement = Feature.SWITCH_EXPRESSION.allowedInSource(source);
          polymorphicSignatureScope = WriteableScope.create(syms.noSymbol);
          allowModules = Feature.MODULES.allowedInSource(source);
          allowRecords = Feature.RECORDS.allowedInSource(source);
          dumpMethodReferenceSearchResults = options.isSet("debug.dumpMethodReferenceSearchResults");
+         allowValueClasses = Feature.VALUE_CLASSES.allowedInSource(source);
+         allowPrimitiveClasses = Feature.PRIMITIVE_CLASSES.allowedInSource(source) && options.isSet("enablePrimitiveClasses");
      }
  
      /** error symbols, which are returned when resolution fails
       */
      private final SymbolNotFoundError varNotFound;

*** 216,11 ***
              return;
          } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
              return;
          }
  
!         if (bestSoFar.name == names.init &&
                  bestSoFar.owner == syms.objectType.tsym &&
                  !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
              return; //skip diags for Object constructor resolution
          } else if (site == syms.predefClass.type &&
                  !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
--- 218,11 ---
              return;
          } else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
              return;
          }
  
!         if (names.isInitOrVNew(bestSoFar.name) &&
                  bestSoFar.owner == syms.objectType.tsym &&
                  !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
              return; //skip diags for Object constructor resolution
          } else if (site == syms.predefClass.type &&
                  !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {

*** 289,11 ***
      /** An environment is an "initializer" if it is a constructor or
       *  an instance initializer.
       */
      static boolean isInitializer(Env<AttrContext> env) {
          Symbol owner = env.info.scope.owner;
!         return owner.isConstructor() ||
              owner.owner.kind == TYP &&
              (owner.kind == VAR ||
               owner.kind == MTH && (owner.flags() & BLOCK) != 0) &&
              (owner.flags() & STATIC) == 0;
      }
--- 291,11 ---
      /** An environment is an "initializer" if it is a constructor or
       *  an instance initializer.
       */
      static boolean isInitializer(Env<AttrContext> env) {
          Symbol owner = env.info.scope.owner;
!         return owner.isInitOrVNew() ||
              owner.owner.kind == TYP &&
              (owner.kind == VAR ||
               owner.kind == MTH && (owner.flags() & BLOCK) != 0) &&
              (owner.flags() & STATIC) == 0;
      }

*** 401,11 ***
       */
      public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym) {
          return isAccessible(env, site, sym, false);
      }
      public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) {
!         if (sym.name == names.init && sym.owner != site.tsym) return false;
  
          /* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor
             to refer to an inaccessible type
          */
          if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0)
--- 403,11 ---
       */
      public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym) {
          return isAccessible(env, site, sym, false);
      }
      public boolean isAccessible(Env<AttrContext> env, Type site, Symbol sym, boolean checkInner) {
!         if (names.isInitOrVNew(sym.name) && sym.owner != site.tsym) return false;
  
          /* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor
             to refer to an inaccessible type
          */
          if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0)

*** 414,64 ***
          if (env.info.visitingServiceImplementation &&
              env.toplevel.modle == sym.packge().modle) {
              return true;
          }
  
!         switch ((short)(sym.flags() & AccessFlags)) {
!         case PRIVATE:
!             return
!                 (env.enclClass.sym == sym.owner // fast special case
!                  ||
!                  env.enclClass.sym.outermostClass() ==
!                  sym.owner.outermostClass())
!                 &&
!                 sym.isInheritedIn(site.tsym, types);
!         case 0:
!             return
!                 (env.toplevel.packge == sym.owner.owner // fast special case
!                  ||
!                  env.toplevel.packge == sym.packge())
!                 &&
!                 isAccessible(env, site, checkInner)
!                 &&
!                 sym.isInheritedIn(site.tsym, types)
!                 &&
!                 notOverriddenIn(site, sym);
!         case PROTECTED:
!             return
!                 (env.toplevel.packge == sym.owner.owner // fast special case
!                  ||
!                  env.toplevel.packge == sym.packge()
!                  ||
!                  isProtectedAccessible(sym, env.enclClass.sym, site)
!                  ||
!                  // OK to select instance method or field from 'super' or type name
!                  // (but type names should be disallowed elsewhere!)
!                  env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP)
!                 &&
!                 isAccessible(env, site, checkInner)
!                 &&
!                 notOverriddenIn(site, sym);
!         default: // this case includes erroneous combinations as well
!             return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym);
          }
      }
      //where
      /* `sym' is accessible only if not overridden by
       * another symbol which is a member of `site'
       * (because, if it is overridden, `sym' is not strictly
       * speaking a member of `site'). A polymorphic signature method
       * cannot be overridden (e.g. MH.invokeExact(Object[])).
       */
      private boolean notOverriddenIn(Type site, Symbol sym) {
!         if (sym.kind != MTH || sym.isConstructor() || sym.isStatic())
              return true;
!         else {
!             Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
!             return (s2 == null || s2 == sym || sym.owner == s2.owner || (sym.owner.isInterface() && s2.owner == syms.objectType.tsym) ||
!                     !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
          }
      }
      //where
          /** Is given protected symbol accessible if it is selected from given site
           *  and the selection takes place in given class?
           *  @param sym     The symbol with protected access
--- 416,89 ---
          if (env.info.visitingServiceImplementation &&
              env.toplevel.modle == sym.packge().modle) {
              return true;
          }
  
!         ClassSymbol enclosingCsym = env.enclClass.sym;
!         if (allowPrimitiveClasses) {
!             if (sym.kind == MTH || sym.kind == VAR) {
!                 /* If any primitive class types are involved, ask the same question in the reference universe,
!                    where the hierarchy is navigable
!                 */
!                 if (site.isPrimitiveClass())
!                     site = site.referenceProjection();
!             } else if (sym.kind == TYP) {
!                 // A type is accessible in a reference projection if it was
!                 // accessible in the value projection.
!                 if (site.isReferenceProjection())
!                     site = site.valueProjection();
!             }
!         }
!         try {
!             switch ((short)(sym.flags() & AccessFlags)) {
!                 case PRIVATE:
!                     return
!                             (env.enclClass.sym == sym.owner // fast special case
!                                     ||
!                                     env.enclClass.sym.outermostClass() ==
!                                             sym.owner.outermostClass())
!                                     &&
!                                     sym.isInheritedIn(site.tsym, types);
!                 case 0:
!                     return
!                             (env.toplevel.packge == sym.owner.owner // fast special case
!                                     ||
!                                     env.toplevel.packge == sym.packge())
!                                     &&
!                                     isAccessible(env, site, checkInner)
!                                     &&
!                                     sym.isInheritedIn(site.tsym, types)
!                                     &&
!                                     notOverriddenIn(site, sym);
!                 case PROTECTED:
+                     return
+                             (env.toplevel.packge == sym.owner.owner // fast special case
+                                     ||
+                                     env.toplevel.packge == sym.packge()
+                                     ||
+                                     isProtectedAccessible(sym, env.enclClass.sym, site)
+                                     ||
+                                     // OK to select instance method or field from 'super' or type name
+                                     // (but type names should be disallowed elsewhere!)
+                                     env.info.selectSuper && (sym.flags() & STATIC) == 0 && sym.kind != TYP)
+                                     &&
+                                     isAccessible(env, site, checkInner)
+                                     &&
+                                     notOverriddenIn(site, sym);
+                 default: // this case includes erroneous combinations as well
+                     return isAccessible(env, site, checkInner) && notOverriddenIn(site, sym);
+             }
+         } finally {
+             env.enclClass.sym = enclosingCsym;
          }
      }
      //where
      /* `sym' is accessible only if not overridden by
       * another symbol which is a member of `site'
       * (because, if it is overridden, `sym' is not strictly
       * speaking a member of `site'). A polymorphic signature method
       * cannot be overridden (e.g. MH.invokeExact(Object[])).
       */
      private boolean notOverriddenIn(Type site, Symbol sym) {
!         if (sym.kind != MTH || sym.isInitOrVNew() || sym.isStatic())
              return true;
! 
!         /* If any primitive class types are involved, ask the same question in the reference universe,
!            where the hierarchy is navigable
!         */
+         if (allowPrimitiveClasses && site.isPrimitiveClass()) {
+             site = site.referenceProjection();
          }
+ 
+         Symbol s2 = ((MethodSymbol)sym).implementation(site.tsym, types, true);
+         return (s2 == null || s2 == sym || sym.owner == s2.owner || (sym.owner.isInterface() && s2.owner == syms.objectType.tsym) ||
+                 !types.isSubSignature(types.memberType(site, s2), types.memberType(site, sym)));
      }
      //where
          /** Is given protected symbol accessible if it is selected from given site
           *  and the selection takes place in given class?
           *  @param sym     The symbol with protected access

*** 1687,16 ***
                  TypeSymbol m2Owner = (TypeSymbol)m2.owner;
                  // the two owners can never be the same if the target methods are compiled from source,
                  // but we need to protect against cases where the methods are defined in some classfile
                  // and make sure we issue an ambiguity error accordingly (by skipping the logic below).
                  if (m1Owner != m2Owner) {
!                     if (types.asSuper(m1Owner.type, m2Owner) != null &&
                          ((m1.owner.flags_field & INTERFACE) == 0 ||
                           (m2.owner.flags_field & INTERFACE) != 0) &&
                          m1.overrides(m2, m1Owner, types, false))
                          return m1;
!                     if (types.asSuper(m2Owner.type, m1Owner) != null &&
                          ((m2.owner.flags_field & INTERFACE) == 0 ||
                           (m1.owner.flags_field & INTERFACE) != 0) &&
                          m2.overrides(m1, m2Owner, types, false))
                          return m2;
                  }
--- 1714,16 ---
                  TypeSymbol m2Owner = (TypeSymbol)m2.owner;
                  // the two owners can never be the same if the target methods are compiled from source,
                  // but we need to protect against cases where the methods are defined in some classfile
                  // and make sure we issue an ambiguity error accordingly (by skipping the logic below).
                  if (m1Owner != m2Owner) {
!                     if (types.asSuper(m1Owner.type.referenceProjectionOrSelf(), m2Owner) != null &&
                          ((m1.owner.flags_field & INTERFACE) == 0 ||
                           (m2.owner.flags_field & INTERFACE) != 0) &&
                          m1.overrides(m2, m1Owner, types, false))
                          return m1;
!                     if (types.asSuper(m2Owner.type.referenceProjectionOrSelf(), m1Owner) != null &&
                          ((m2.owner.flags_field & INTERFACE) == 0 ||
                           (m1.owner.flags_field & INTERFACE) != 0) &&
                          m2.overrides(m1, m2Owner, types, false))
                          return m2;
                  }

*** 1859,11 ***
          InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
          boolean isInterface = site.tsym.isInterface();
          for (TypeSymbol s : isInterface ? List.of(intype.tsym) : superclasses(intype)) {
              bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
                      s.members(), bestSoFar, allowBoxing, useVarargs, true);
!             if (name == names.init) return bestSoFar;
              iphase = (iphase == null) ? null : iphase.update(s, this);
              if (iphase != null) {
                  for (Type itype : types.interfaces(s.type)) {
                      itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]);
                  }
--- 1886,11 ---
          InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
          boolean isInterface = site.tsym.isInterface();
          for (TypeSymbol s : isInterface ? List.of(intype.tsym) : superclasses(intype)) {
              bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes,
                      s.members(), bestSoFar, allowBoxing, useVarargs, true);
!             if (names.isInitOrVNew(name)) return bestSoFar;
              iphase = (iphase == null) ? null : iphase.update(s, this);
              if (iphase != null) {
                  for (Type itype : types.interfaces(s.type)) {
                      itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]);
                  }

*** 2294,10 ***
--- 2321,26 ---
       */
      Symbol findMemberType(Env<AttrContext> env,
                            Type site,
                            Name name,
                            TypeSymbol c) {
+         return findMemberTypeInternal(env,site, name, c);
+     }
+ 
+     /** Find qualified member type.
+      *  @param env       The current environment.
+      *  @param site      The original type from where the selection takes
+      *                   place.
+      *  @param name      The type's name.
+      *  @param c         The class to search for the member type. This is
+      *                   always a superclass or implemented interface of
+      *                   site's class.
+      */
+     Symbol findMemberTypeInternal(Env<AttrContext> env,
+                           Type site,
+                           Name name,
+                           TypeSymbol c) {
          Symbol sym = findImmediateMemberType(env, site, name, c);
  
          if (sym != typeNotFound)
              return sym;
  

*** 2342,10 ***
--- 2385,18 ---
      /** Find an unqualified type symbol.
       *  @param env       The current environment.
       *  @param name      The type's name.
       */
      Symbol findType(Env<AttrContext> env, Name name) {
+         return findTypeInternal(env, name);
+     }
+ 
+     /** Find an unqualified type symbol.
+      *  @param env       The current environment.
+      *  @param name      The type's name.
+      */
+     Symbol findTypeInternal(Env<AttrContext> env, Name name) {
          if (name == names.empty)
              return typeNotFound; // do not allow inadvertent "lookup" of anonymous types
          Symbol bestSoFar = typeNotFound;
          Symbol sym;
          boolean staticOnly = false;

*** 2880,11 ***
                                final DiagnosticPosition pos,
                                Env<AttrContext> env,
                                Type site,
                                List<Type> argtypes,
                                List<Type> typeargtypes) {
!         return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
              @Override
              Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
                  return findConstructor(pos, env, site, argtypes, typeargtypes,
                          phase.isBoxingRequired(),
                          phase.isVarargsRequired());
--- 2931,12 ---
                                final DiagnosticPosition pos,
                                Env<AttrContext> env,
                                Type site,
                                List<Type> argtypes,
                                List<Type> typeargtypes) {
!         Name constructorName = site.tsym.isConcreteValueClass() ? names.vnew : names.init;
+         return lookupMethod(env, pos, site.tsym, resolveContext, new BasicLookupHelper(constructorName, site, argtypes, typeargtypes) {
              @Override
              Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
                  return findConstructor(pos, env, site, argtypes, typeargtypes,
                          phase.isBoxingRequired(),
                          phase.isVarargsRequired());

*** 2914,12 ***
      Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
                                Type site, List<Type> argtypes,
                                List<Type> typeargtypes,
                                boolean allowBoxing,
                                boolean useVarargs) {
          Symbol sym = findMethod(env, site,
!                                     names.init, argtypes,
                                      typeargtypes, allowBoxing,
                                      useVarargs);
          chk.checkDeprecated(pos, env.info.scope.owner, sym);
          chk.checkPreview(pos, env.info.scope.owner, sym);
          return sym;
--- 2966,13 ---
      Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env,
                                Type site, List<Type> argtypes,
                                List<Type> typeargtypes,
                                boolean allowBoxing,
                                boolean useVarargs) {
+         Name constructorName = site.tsym.isConcreteValueClass() ? names.vnew : names.init;
          Symbol sym = findMethod(env, site,
!                                     constructorName, argtypes,
                                      typeargtypes, allowBoxing,
                                      useVarargs);
          chk.checkDeprecated(pos, env.info.scope.owner, sym);
          chk.checkPreview(pos, env.info.scope.owner, sym);
          return sym;

*** 2938,12 ***
      Symbol resolveDiamond(DiagnosticPosition pos,
                                Env<AttrContext> env,
                                Type site,
                                List<Type> argtypes,
                                List<Type> typeargtypes) {
          return lookupMethod(env, pos, site.tsym, resolveMethodCheck,
!                 new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
                      @Override
                      Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
                          return findDiamond(pos, env, site, argtypes, typeargtypes,
                                  phase.isBoxingRequired(),
                                  phase.isVarargsRequired());
--- 2991,13 ---
      Symbol resolveDiamond(DiagnosticPosition pos,
                                Env<AttrContext> env,
                                Type site,
                                List<Type> argtypes,
                                List<Type> typeargtypes) {
+         Name constructorName = allowValueClasses && site.tsym.isConcreteValueClass() ? names.vnew : names.init;
          return lookupMethod(env, pos, site.tsym, resolveMethodCheck,
!                 new BasicLookupHelper(constructorName, site, argtypes, typeargtypes) {
                      @Override
                      Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
                          return findDiamond(pos, env, site, argtypes, typeargtypes,
                                  phase.isBoxingRequired(),
                                  phase.isVarargsRequired());

*** 2954,11 ***
                              if (sym.kind != WRONG_MTH &&
                                  sym.kind != WRONG_MTHS) {
                                  sym = super.access(env, pos, location, sym);
                              } else {
                                  sym = new DiamondError(sym, currentResolutionContext);
!                                 sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
                                  env.info.pendingResolutionPhase = currentResolutionContext.step;
                              }
                          }
                          return sym;
                      }});
--- 3008,11 ---
                              if (sym.kind != WRONG_MTH &&
                                  sym.kind != WRONG_MTHS) {
                                  sym = super.access(env, pos, location, sym);
                              } else {
                                  sym = new DiamondError(sym, currentResolutionContext);
!                                 sym = accessMethod(sym, pos, site, constructorName, true, argtypes, typeargtypes);
                                  env.info.pendingResolutionPhase = currentResolutionContext.step;
                              }
                          }
                          return sym;
                      }});

*** 3001,20 ***
                                List<Type> typeargtypes,
                                boolean allowBoxing,
                                boolean useVarargs) {
          Symbol bestSoFar = methodNotFound;
          TypeSymbol tsym = site.tsym.isInterface() ? syms.objectType.tsym : site.tsym;
!         for (final Symbol sym : tsym.members().getSymbolsByName(names.init)) {
              //- System.out.println(" e " + e.sym);
              if (sym.kind == MTH &&
                  (sym.flags_field & SYNTHETIC) == 0) {
                      List<Type> oldParams = sym.type.hasTag(FORALL) ?
                              ((ForAll)sym.type).tvars :
                              List.nil();
                      Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams),
                                                   types.createMethodTypeWithReturn(sym.type.asMethodType(), site));
!                     MethodSymbol newConstr = new MethodSymbol(sym.flags(), names.init, constrType, site.tsym) {
                          @Override
                          public Symbol baseSymbol() {
                              return sym;
                          }
                      };
--- 3055,21 ---
                                List<Type> typeargtypes,
                                boolean allowBoxing,
                                boolean useVarargs) {
          Symbol bestSoFar = methodNotFound;
          TypeSymbol tsym = site.tsym.isInterface() ? syms.objectType.tsym : site.tsym;
!         Name constructorName = site.tsym.isConcreteValueClass() ? names.vnew : names.init;
+         for (final Symbol sym : tsym.members().getSymbolsByName(constructorName)) {
              //- System.out.println(" e " + e.sym);
              if (sym.kind == MTH &&
                  (sym.flags_field & SYNTHETIC) == 0) {
                      List<Type> oldParams = sym.type.hasTag(FORALL) ?
                              ((ForAll)sym.type).tvars :
                              List.nil();
                      Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams),
                                                   types.createMethodTypeWithReturn(sym.type.asMethodType(), site));
!                     MethodSymbol newConstr = new MethodSymbol(sym.flags(), constructorName, constrType, site.tsym) {
                          @Override
                          public Symbol baseSymbol() {
                              return sym;
                          }
                      };

*** 3052,11 ***
                                    Type site,
                                    Name name,
                                    List<Type> argtypes,
                                    List<Type> typeargtypes,
                                    MethodResolutionPhase maxPhase) {
!         if (!name.equals(names.init)) {
              //method reference
              return new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
          } else if (site.hasTag(ARRAY)) {
              //array constructor reference
              return new ArrayConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase);
--- 3107,11 ---
                                    Type site,
                                    Name name,
                                    List<Type> argtypes,
                                    List<Type> typeargtypes,
                                    MethodResolutionPhase maxPhase) {
!         if (!names.isInitOrVNew(name)) {
              //method reference
              return new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
          } else if (site.hasTag(ARRAY)) {
              //array constructor reference
              return new ArrayConstructorReferenceLookupHelper(referenceTree, site, argtypes, typeargtypes, maxPhase);

*** 3566,11 ***
          @Override
          ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) {
              if (TreeInfo.isStaticSelector(referenceTree.expr, names)) {
                  if (argtypes.nonEmpty() &&
                          (argtypes.head.hasTag(NONE) ||
!                         types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), originalSite))) {
                      return new UnboundMethodReferenceLookupHelper(referenceTree, name,
                              originalSite, argtypes, typeargtypes, maxPhase);
                  } else {
                      return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) {
                          @Override
--- 3621,11 ---
          @Override
          ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) {
              if (TreeInfo.isStaticSelector(referenceTree.expr, names)) {
                  if (argtypes.nonEmpty() &&
                          (argtypes.head.hasTag(NONE) ||
!                         types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head.referenceProjectionOrSelf()), originalSite))) {
                      return new UnboundMethodReferenceLookupHelper(referenceTree, name,
                              originalSite, argtypes, typeargtypes, maxPhase);
                  } else {
                      return new ReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase) {
                          @Override

*** 3619,11 ***
  
          UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
                  List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
              super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase);
              if (site.isRaw() && !argtypes.head.hasTag(NONE)) {
!                 Type asSuperSite = types.asSuper(argtypes.head, site.tsym);
                  this.site = types.skipTypeVars(asSuperSite, true);
              }
          }
  
          @Override
--- 3674,11 ---
  
          UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
                  List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
              super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase);
              if (site.isRaw() && !argtypes.head.hasTag(NONE)) {
!                 Type asSuperSite = types.asSuper(argtypes.head.referenceProjectionOrSelf(), site.tsym);
                  this.site = types.skipTypeVars(asSuperSite, true);
              }
          }
  
          @Override

*** 3644,11 ***
       */
      class ArrayConstructorReferenceLookupHelper extends ReferenceLookupHelper {
  
          ArrayConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
                  List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
!             super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase);
          }
  
          @Override
          protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
              WriteableScope sc = WriteableScope.create(syms.arrayClass);
--- 3699,12 ---
       */
      class ArrayConstructorReferenceLookupHelper extends ReferenceLookupHelper {
  
          ArrayConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
                  List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
!             // TODO - array constructor will be <init>
+             super(referenceTree, site.tsym.isConcreteValueClass() ? names.vnew : names.init, site, argtypes, typeargtypes, maxPhase);
          }
  
          @Override
          protected Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
              WriteableScope sc = WriteableScope.create(syms.arrayClass);

*** 3676,15 ***
  
          boolean needsInference;
  
          ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
                  List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
!             super(referenceTree, names.init, site, argtypes, typeargtypes, maxPhase);
              if (site.isRaw()) {
                  this.site = new ClassType(site.getEnclosingType(),
                          !(site.tsym.isInner() && site.getEnclosingType().isRaw()) ?
!                                 site.tsym.type.getTypeArguments() : List.nil(), site.tsym, site.getMetadata());
                  needsInference = true;
              }
          }
  
          @Override
--- 3732,15 ---
  
          boolean needsInference;
  
          ConstructorReferenceLookupHelper(JCMemberReference referenceTree, Type site, List<Type> argtypes,
                  List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
!             super(referenceTree, site.tsym.isConcreteValueClass() ? names.vnew : names.init, site, argtypes, typeargtypes, maxPhase);
              if (site.isRaw()) {
                  this.site = new ClassType(site.getEnclosingType(),
                          !(site.tsym.isInner() && site.getEnclosingType().isRaw()) ?
!                             site.tsym.type.getTypeArguments() : List.nil(), site.tsym, site.getMetadata(), site.getFlavor());
                  needsInference = true;
              }
          }
  
          @Override

*** 3770,11 ***
              //this might be a default super call if one of the superinterfaces is 'c'
              for (Type t : pruneInterfaces(env.enclClass.type)) {
                  if (t.tsym == c) {
                      env.info.defaultSuperCallSite = t;
                      return new VarSymbol(0, names._super,
!                             types.asSuper(env.enclClass.type, c), env.enclClass.sym);
                  }
              }
              //find a direct supertype that is a subtype of 'c'
              for (Type i : types.directSupertypes(env.enclClass.type)) {
                  if (i.tsym.isSubClass(c, types) && i.tsym != c) {
--- 3826,11 ---
              //this might be a default super call if one of the superinterfaces is 'c'
              for (Type t : pruneInterfaces(env.enclClass.type)) {
                  if (t.tsym == c) {
                      env.info.defaultSuperCallSite = t;
                      return new VarSymbol(0, names._super,
!                             types.asSuper(env.enclClass.type.referenceProjectionOrSelf(), c), env.enclClass.sym);
                  }
              }
              //find a direct supertype that is a subtype of 'c'
              for (Type i : types.directSupertypes(env.enclClass.type)) {
                  if (i.tsym.isSubClass(c, types) && i.tsym != c) {

*** 4083,11 ***
                          "doesnt.exist", location);
                  }
                  hasLocation = !location.name.equals(names._this) &&
                          !location.name.equals(names._super);
              }
!             boolean isConstructor = name == names.init;
              KindName kindname = isConstructor ? KindName.CONSTRUCTOR : kind.absentKind();
              Name idname = isConstructor ? site.tsym.name : name;
              String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
              if (hasLocation) {
                  return diags.create(dkind, log.currentSource(), pos,
--- 4139,11 ---
                          "doesnt.exist", location);
                  }
                  hasLocation = !location.name.equals(names._this) &&
                          !location.name.equals(names._super);
              }
!             boolean isConstructor = names.isInitOrVNew(name);
              KindName kindname = isConstructor ? KindName.CONSTRUCTOR : kind.absentKind();
              Name idname = isConstructor ? site.tsym.name : name;
              String errKey = getErrorKey(kindname, typeargtypes.nonEmpty(), hasLocation);
              if (hasLocation) {
                  return diags.create(dkind, log.currentSource(), pos,

*** 4175,11 ***
              return diags.create(dkind, log.currentSource(), pos,
                        "cant.apply.symbol",
                        compactMethodDiags ?
                                d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
                        kindName(ws),
!                       ws.name == names.init ? ws.owner.name : ws.name,
                        methodArguments(ws.type.getParameterTypes()),
                        methodArguments(argtypes),
                        kindName(ws.owner),
                        ws.owner.type,
                        c.snd);
--- 4231,11 ---
              return diags.create(dkind, log.currentSource(), pos,
                        "cant.apply.symbol",
                        compactMethodDiags ?
                                d -> MethodResolutionDiagHelper.rewrite(diags, pos, log.currentSource(), dkind, c.snd) : null,
                        kindName(ws),
!                       names.isInitOrVNew(ws.name) ? ws.owner.name : ws.name,
                        methodArguments(ws.type.getParameterTypes()),
                        methodArguments(argtypes),
                        kindName(ws.owner),
                        ws.owner.type,
                        c.snd);

*** 4231,20 ***
              if (filteredCandidates.isEmpty()) {
                  filteredCandidates = candidatesMap;
              }
              boolean truncatedDiag = candidatesMap.size() != filteredCandidates.size();
              if (filteredCandidates.size() > 1) {
                  JCDiagnostic err = diags.create(dkind,
                          null,
                          truncatedDiag ?
                                  EnumSet.of(DiagnosticFlag.COMPRESSED) :
                                  EnumSet.noneOf(DiagnosticFlag.class),
                          log.currentSource(),
                          pos,
                          "cant.apply.symbols",
!                         name == names.init ? KindName.CONSTRUCTOR : kind.absentKind(),
!                         name == names.init ? site.tsym.name : name,
                          methodArguments(argtypes));
                  return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
              } else if (filteredCandidates.size() == 1) {
                  Map.Entry<Symbol, JCDiagnostic> _e =
                                  filteredCandidates.entrySet().iterator().next();
--- 4287,21 ---
              if (filteredCandidates.isEmpty()) {
                  filteredCandidates = candidatesMap;
              }
              boolean truncatedDiag = candidatesMap.size() != filteredCandidates.size();
              if (filteredCandidates.size() > 1) {
+                 boolean isConstructor = names.isInitOrVNew(name);
                  JCDiagnostic err = diags.create(dkind,
                          null,
                          truncatedDiag ?
                                  EnumSet.of(DiagnosticFlag.COMPRESSED) :
                                  EnumSet.noneOf(DiagnosticFlag.class),
                          log.currentSource(),
                          pos,
                          "cant.apply.symbols",
!                         isConstructor ? KindName.CONSTRUCTOR : kind.absentKind(),
!                         isConstructor ? site.tsym.name : name,
                          methodArguments(argtypes));
                  return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(filteredCandidates, site));
              } else if (filteredCandidates.size() == 1) {
                  Map.Entry<Symbol, JCDiagnostic> _e =
                                  filteredCandidates.entrySet().iterator().next();

*** 4400,11 ***
                  Symbol location,
                  Type site,
                  Name name,
                  List<Type> argtypes,
                  List<Type> typeargtypes) {
!             if (sym.name == names.init && sym.owner != site.tsym) {
                  return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
                          pos, location, site, name, argtypes, typeargtypes);
              }
              else if ((sym.flags() & PUBLIC) != 0
                  || (env != null && this.site != null
--- 4457,11 ---
                  Symbol location,
                  Type site,
                  Name name,
                  List<Type> argtypes,
                  List<Type> typeargtypes) {
!             if (names.isInitOrVNew(sym.name) && sym.owner != site.tsym) {
                  return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
                          pos, location, site, name, argtypes, typeargtypes);
              }
              else if ((sym.flags() & PUBLIC) != 0
                  || (env != null && this.site != null

*** 4613,11 ***
                  List<Type> typeargtypes) {
              List<Symbol> diagSyms = ambiguousSyms.reverse();
              Symbol s1 = diagSyms.head;
              Symbol s2 = diagSyms.tail.head;
              Name sname = s1.name;
!             if (sname == names.init) sname = s1.owner.name;
              return diags.create(dkind, log.currentSource(),
                      pos, "ref.ambiguous", sname,
                      kindName(s1),
                      s1,
                      s1.location(site, types),
--- 4670,11 ---
                  List<Type> typeargtypes) {
              List<Symbol> diagSyms = ambiguousSyms.reverse();
              Symbol s1 = diagSyms.head;
              Symbol s2 = diagSyms.tail.head;
              Name sname = s1.name;
!             if (names.isInitOrVNew(sname)) sname = s1.owner.name;
              return diags.create(dkind, log.currentSource(),
                      pos, "ref.ambiguous", sname,
                      kindName(s1),
                      s1,
                      s1.location(site, types),
< prev index next >