646 : t); |
646 : t); |
647 else |
647 else |
648 return t; |
648 return t; |
649 } |
649 } |
650 |
650 |
|
651 /** Check that type is a valid qualifier for a constructor reference expression |
|
652 */ |
|
653 Type checkConstructorRefType(DiagnosticPosition pos, Type t) { |
|
654 t = checkClassType(pos, t); |
|
655 if (t.tag == CLASS) { |
|
656 if ((t.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) { |
|
657 log.error(pos, "abstract.cant.be.instantiated"); |
|
658 t = types.createErrorType(t); |
|
659 } else if ((t.tsym.flags() & ENUM) != 0) { |
|
660 log.error(pos, "enum.cant.be.instantiated"); |
|
661 t = types.createErrorType(t); |
|
662 } |
|
663 } |
|
664 return t; |
|
665 } |
|
666 |
651 /** Check that type is a class or interface type. |
667 /** Check that type is a class or interface type. |
652 * @param pos Position to be used for error reporting. |
668 * @param pos Position to be used for error reporting. |
653 * @param t The type to be checked. |
669 * @param t The type to be checked. |
654 * @param noBounds True if type bounds are illegal here. |
670 * @param noBounds True if type bounds are illegal here. |
655 */ |
671 */ |
840 sym.owner == syms.enumSym) |
856 sym.owner == syms.enumSym) |
841 formals = formals.tail.tail; |
857 formals = formals.tail.tail; |
842 List<JCExpression> args = argtrees; |
858 List<JCExpression> args = argtrees; |
843 DeferredAttr.DeferredTypeMap checkDeferredMap = |
859 DeferredAttr.DeferredTypeMap checkDeferredMap = |
844 deferredAttr.new DeferredTypeMap(DeferredAttr.AttrMode.CHECK, sym, env.info.pendingResolutionPhase); |
860 deferredAttr.new DeferredTypeMap(DeferredAttr.AttrMode.CHECK, sym, env.info.pendingResolutionPhase); |
845 while (formals.head != last) { |
861 if (args != null) { |
846 JCTree arg = args.head; |
862 //this is null when type-checking a method reference |
847 Warner warn = convertWarner(arg.pos(), arg.type, formals.head); |
863 while (formals.head != last) { |
848 assertConvertible(arg, arg.type, formals.head, warn); |
|
849 args = args.tail; |
|
850 formals = formals.tail; |
|
851 } |
|
852 if (useVarargs) { |
|
853 Type varArg = types.elemtype(last); |
|
854 while (args.tail != null) { |
|
855 JCTree arg = args.head; |
864 JCTree arg = args.head; |
856 Warner warn = convertWarner(arg.pos(), arg.type, varArg); |
865 Warner warn = convertWarner(arg.pos(), arg.type, formals.head); |
857 assertConvertible(arg, arg.type, varArg, warn); |
866 assertConvertible(arg, arg.type, formals.head, warn); |
858 args = args.tail; |
867 args = args.tail; |
859 } |
868 formals = formals.tail; |
860 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { |
869 } |
861 // non-varargs call to varargs method |
870 if (useVarargs) { |
862 Type varParam = owntype.getParameterTypes().last(); |
871 Type varArg = types.elemtype(last); |
863 Type lastArg = checkDeferredMap.apply(argtypes.last()); |
872 while (args.tail != null) { |
864 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
873 JCTree arg = args.head; |
865 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
874 Warner warn = convertWarner(arg.pos(), arg.type, varArg); |
866 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", |
875 assertConvertible(arg, arg.type, varArg, warn); |
867 types.elemtype(varParam), varParam); |
876 args = args.tail; |
|
877 } |
|
878 } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) { |
|
879 // non-varargs call to varargs method |
|
880 Type varParam = owntype.getParameterTypes().last(); |
|
881 Type lastArg = checkDeferredMap.apply(argtypes.last()); |
|
882 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && |
|
883 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) |
|
884 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", |
|
885 types.elemtype(varParam), varParam); |
|
886 } |
868 } |
887 } |
869 if (unchecked) { |
888 if (unchecked) { |
870 warnUnchecked(env.tree.pos(), |
889 warnUnchecked(env.tree.pos(), |
871 "unchecked.meth.invocation.applied", |
890 "unchecked.meth.invocation.applied", |
872 kindName(sym), |
891 kindName(sym), |