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

changeset 1959
55da6b3a6940
parent 1956
f657d400c736
child 1978
7bf6313e1ced
equal deleted inserted replaced
1958:389eaf6ed973 1959:55da6b3a6940
873 }); 873 });
874 return mtype; 874 return mtype;
875 } 875 }
876 Type owntype = mtype; 876 Type owntype = mtype;
877 List<Type> formals = owntype.getParameterTypes(); 877 List<Type> formals = owntype.getParameterTypes();
878 List<Type> nonInferred = sym.type.getParameterTypes();
879 if (nonInferred.length() != formals.length()) nonInferred = formals;
878 Type last = useVarargs ? formals.last() : null; 880 Type last = useVarargs ? formals.last() : null;
879 if (sym.name == names.init && 881 if (sym.name == names.init && sym.owner == syms.enumSym) {
880 sym.owner == syms.enumSym) 882 formals = formals.tail.tail;
881 formals = formals.tail.tail; 883 nonInferred = nonInferred.tail.tail;
884 }
882 List<JCExpression> args = argtrees; 885 List<JCExpression> args = argtrees;
883 if (args != null) { 886 if (args != null) {
884 //this is null when type-checking a method reference 887 //this is null when type-checking a method reference
885 while (formals.head != last) { 888 while (formals.head != last) {
886 JCTree arg = args.head; 889 JCTree arg = args.head;
887 Warner warn = convertWarner(arg.pos(), arg.type, formals.head); 890 Warner warn = convertWarner(arg.pos(), arg.type, nonInferred.head);
888 assertConvertible(arg, arg.type, formals.head, warn); 891 assertConvertible(arg, arg.type, formals.head, warn);
889 args = args.tail; 892 args = args.tail;
890 formals = formals.tail; 893 formals = formals.tail;
894 nonInferred = nonInferred.tail;
891 } 895 }
892 if (useVarargs) { 896 if (useVarargs) {
893 Type varArg = types.elemtype(last); 897 Type varArg = types.elemtype(last);
894 while (args.tail != null) { 898 while (args.tail != null) {
895 JCTree arg = args.head; 899 JCTree arg = args.head;
901 allowVarargs) { 905 allowVarargs) {
902 // non-varargs call to varargs method 906 // non-varargs call to varargs method
903 Type varParam = owntype.getParameterTypes().last(); 907 Type varParam = owntype.getParameterTypes().last();
904 Type lastArg = argtypes.last(); 908 Type lastArg = argtypes.last();
905 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) && 909 if (types.isSubtypeUnchecked(lastArg, types.elemtype(varParam)) &&
906 !types.isSameType(types.erasure(varParam), types.erasure(lastArg))) 910 !types.isSameType(types.erasure(varParam), types.erasure(lastArg)))
907 log.warning(argtrees.last().pos(), "inexact.non-varargs.call", 911 log.warning(argtrees.last().pos(), "inexact.non-varargs.call",
908 types.elemtype(varParam), varParam); 912 types.elemtype(varParam), varParam);
909 } 913 }
910 } 914 }
911 if (useVarargs) { 915 if (useVarargs) {
912 Type argtype = owntype.getParameterTypes().last(); 916 Type argtype = owntype.getParameterTypes().last();
913 if (!types.isReifiable(argtype) && 917 if (!types.isReifiable(argtype) &&
914 (!allowSimplifiedVarargs || 918 (!allowSimplifiedVarargs ||
915 sym.attribute(syms.trustMeType.tsym) == null || 919 sym.attribute(syms.trustMeType.tsym) == null ||
916 !isTrustMeAllowedOnMethod(sym))) { 920 !isTrustMeAllowedOnMethod(sym))) {
917 warnUnchecked(env.tree.pos(), 921 warnUnchecked(env.tree.pos(),
918 "unchecked.generic.array.creation", 922 "unchecked.generic.array.creation",
919 argtype); 923 argtype);
920 } 924 }
921 if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) { 925 if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) {
927 PolyKind.POLY : PolyKind.STANDALONE; 931 PolyKind.POLY : PolyKind.STANDALONE;
928 TreeInfo.setPolyKind(env.tree, pkind); 932 TreeInfo.setPolyKind(env.tree, pkind);
929 return owntype; 933 return owntype;
930 } 934 }
931 //where 935 //where
932 private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) { 936 private void assertConvertible(JCTree tree, Type actual, Type formal, Warner warn) {
933 if (types.isConvertible(actual, formal, warn)) 937 if (types.isConvertible(actual, formal, warn))
934 return; 938 return;
935 939
936 if (formal.isCompound() 940 if (formal.isCompound()
937 && types.isSubtype(actual, types.supertype(formal)) 941 && types.isSubtype(actual, types.supertype(formal))
938 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn)) 942 && types.isSubtypeUnchecked(actual, types.interfaces(formal), warn))
939 return; 943 return;
940 } 944 }
941 945
942 /** 946 /**
943 * Check that type 't' is a valid instantiation of a generic class 947 * Check that type 't' is a valid instantiation of a generic class
944 * (see JLS 4.5) 948 * (see JLS 4.5)
945 * 949 *

mercurial