src/share/classes/com/sun/tools/javac/comp/Check.java

changeset 1352
d4b3cb1ece84
parent 1348
573ceb23beeb
child 1358
fc123bdeddb8
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Fri Oct 05 14:21:09 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Sat Oct 06 10:35:38 2012 +0100
     1.3 @@ -648,6 +648,22 @@
     1.4              return t;
     1.5      }
     1.6  
     1.7 +    /** Check that type is a valid qualifier for a constructor reference expression
     1.8 +     */
     1.9 +    Type checkConstructorRefType(DiagnosticPosition pos, Type t) {
    1.10 +        t = checkClassType(pos, t);
    1.11 +        if (t.tag == CLASS) {
    1.12 +            if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
    1.13 +                log.error(pos, "abstract.cant.be.instantiated");
    1.14 +                t = types.createErrorType(t);
    1.15 +            } else if ((t.tsym.flags() & ENUM) != 0) {
    1.16 +                log.error(pos, "enum.cant.be.instantiated");
    1.17 +                t = types.createErrorType(t);
    1.18 +            }
    1.19 +        }
    1.20 +        return t;
    1.21 +    }
    1.22 +
    1.23      /** Check that type is a class or interface type.
    1.24       *  @param pos           Position to be used for error reporting.
    1.25       *  @param t             The type to be checked.
    1.26 @@ -842,29 +858,32 @@
    1.27          List<JCExpression> args = argtrees;
    1.28          DeferredAttr.DeferredTypeMap checkDeferredMap =
    1.29                  deferredAttr.new DeferredTypeMap(DeferredAttr.AttrMode.CHECK, sym, env.info.pendingResolutionPhase);
    1.30 -        while (formals.head != last) {
    1.31 -            JCTree arg = args.head;
    1.32 -            Warner warn = convertWarner(arg.pos(), arg.type, formals.head);
    1.33 -            assertConvertible(arg, arg.type, formals.head, warn);
    1.34 -            args = args.tail;
    1.35 -            formals = formals.tail;
    1.36 -        }
    1.37 -        if (useVarargs) {
    1.38 -            Type varArg = types.elemtype(last);
    1.39 -            while (args.tail != null) {
    1.40 +        if (args != null) {
    1.41 +            //this is null when type-checking a method reference
    1.42 +            while (formals.head != last) {
    1.43                  JCTree arg = args.head;
    1.44 -                Warner warn = convertWarner(arg.pos(), arg.type, varArg);
    1.45 -                assertConvertible(arg, arg.type, varArg, warn);
    1.46 +                Warner warn = convertWarner(arg.pos(), arg.type, formals.head);
    1.47 +                assertConvertible(arg, arg.type, formals.head, warn);
    1.48                  args = args.tail;
    1.49 +                formals = formals.tail;
    1.50              }
    1.51 -        } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
    1.52 -            // non-varargs call to varargs method
    1.53 -            Type varParam = owntype.getParameterTypes().last();
    1.54 -            Type lastArg = checkDeferredMap.apply(argtypes.last());
    1.55 -            if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
    1.56 -                    !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
    1.57 -                log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
    1.58 -                        types.elemtype(varParam), varParam);
    1.59 +            if (useVarargs) {
    1.60 +                Type varArg = types.elemtype(last);
    1.61 +                while (args.tail != null) {
    1.62 +                    JCTree arg = args.head;
    1.63 +                    Warner warn = convertWarner(arg.pos(), arg.type, varArg);
    1.64 +                    assertConvertible(arg, arg.type, varArg, warn);
    1.65 +                    args = args.tail;
    1.66 +                }
    1.67 +            } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
    1.68 +                // non-varargs call to varargs method
    1.69 +                Type varParam = owntype.getParameterTypes().last();
    1.70 +                Type lastArg = checkDeferredMap.apply(argtypes.last());
    1.71 +                if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
    1.72 +                        !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
    1.73 +                    log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
    1.74 +                            types.elemtype(varParam), varParam);
    1.75 +            }
    1.76          }
    1.77          if (unchecked) {
    1.78              warnUnchecked(env.tree.pos(),
    1.79 @@ -899,6 +918,9 @@
    1.80                  case NEWCLASS:
    1.81                      ((JCNewClass) tree).varargsElement = elemtype;
    1.82                      break;
    1.83 +                case REFERENCE:
    1.84 +                    ((JCMemberReference) tree).varargsElement = elemtype;
    1.85 +                    break;
    1.86                  default:
    1.87                      throw new AssertionError(""+tree);
    1.88              }

mercurial