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

changeset 787
b1c98bfd4709
parent 775
536ee9f126b1
child 789
878c8f760ded
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Dec 10 15:23:42 2010 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Dec 10 15:24:17 2010 +0000
     1.3 @@ -470,7 +470,9 @@
     1.4              throw inapplicableMethodException.setMessage("arg.length.mismatch"); // not enough args
     1.5  
     1.6          if (useVarargs) {
     1.7 -            Type elt = types.elemtype(varargsFormal);
     1.8 +            //note: if applicability check is triggered by most specific test,
     1.9 +            //the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5)
    1.10 +            Type elt = types.elemtypeOrType(varargsFormal);
    1.11              while (argtypes.nonEmpty()) {
    1.12                  if (!types.isConvertible(argtypes.head, elt, warn))
    1.13                      throw inapplicableMethodException.setMessage("varargs.argument.mismatch",
    1.14 @@ -827,24 +829,30 @@
    1.15          List<Type> fromArgs = from.type.getParameterTypes();
    1.16          List<Type> toArgs = to.type.getParameterTypes();
    1.17          if (useVarargs &&
    1.18 -                toArgs.length() < fromArgs.length() &&
    1.19                  (from.flags() & VARARGS) != 0 &&
    1.20                  (to.flags() & VARARGS) != 0) {
    1.21 -            //if we are checking a varargs method 'from' against another varargs
    1.22 -            //method 'to' (where arity of 'to' < arity of 'from') then expand signature
    1.23 -            //of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to'
    1.24 -            //until 'to' signature has the same arity as 'from')
    1.25 -            ListBuffer<Type> args = ListBuffer.lb();
    1.26              Type varargsTypeFrom = fromArgs.last();
    1.27              Type varargsTypeTo = toArgs.last();
    1.28 -            while (fromArgs.head != varargsTypeFrom) {
    1.29 -                args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head);
    1.30 -                fromArgs = fromArgs.tail;
    1.31 -                toArgs = toArgs.head == varargsTypeTo ?
    1.32 -                    toArgs :
    1.33 -                    toArgs.tail;
    1.34 +            ListBuffer<Type> args = ListBuffer.lb();
    1.35 +            if (toArgs.length() < fromArgs.length()) {
    1.36 +                //if we are checking a varargs method 'from' against another varargs
    1.37 +                //method 'to' (where arity of 'to' < arity of 'from') then expand signature
    1.38 +                //of 'to' to 'fit' arity of 'from' (this means adding fake formals to 'to'
    1.39 +                //until 'to' signature has the same arity as 'from')
    1.40 +                while (fromArgs.head != varargsTypeFrom) {
    1.41 +                    args.append(toArgs.head == varargsTypeTo ? types.elemtype(varargsTypeTo) : toArgs.head);
    1.42 +                    fromArgs = fromArgs.tail;
    1.43 +                    toArgs = toArgs.head == varargsTypeTo ?
    1.44 +                        toArgs :
    1.45 +                        toArgs.tail;
    1.46 +                }
    1.47 +            } else {
    1.48 +                //formal argument list is same as original list where last
    1.49 +                //argument (array type) is removed
    1.50 +                args.appendList(toArgs.reverse().tail.reverse());
    1.51              }
    1.52 -            args.append(varargsTypeTo);
    1.53 +            //append varargs element type as last synthetic formal
    1.54 +            args.append(types.elemtype(varargsTypeTo));
    1.55              MethodSymbol msym = new MethodSymbol(to.flags_field,
    1.56                                                   to.name,
    1.57                                                   (Type)to.type.clone(), //see: 6990136

mercurial