6650759: Inference of formal type parameter (unused in formal parameters) is not performed

Tue, 01 Sep 2009 14:53:39 +0100

author
mcimadamore
date
Tue, 01 Sep 2009 14:53:39 +0100
changeset 396
dda7e13f09fb
parent 395
5a72ba18c471
child 397
40a1327a5283

6650759: Inference of formal type parameter (unused in formal parameters) is not performed
Summary: propagate inference constraints from 15.12.2.7 to 15.12.2.8
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Type.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Infer.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6302954/T6476073.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6638712/T6638712b.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6638712/T6638712e.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759a.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759c.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759d.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759e.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759f.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759g.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759h.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759i.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759j.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759k.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759l.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759m.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6650759/T6650759m.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Mon Aug 31 19:43:06 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Sep 01 14:53:39 2009 +0100
     1.3 @@ -1068,7 +1068,7 @@
     1.4  
     1.5          /**
     1.6           * Replaces this ForAll's typevars with a set of concrete Java types
     1.7 -         * and returns the instantiated generic type. Subclasses might override
     1.8 +         * and returns the instantiated generic type. Subclasses should override
     1.9           * in order to check that the list of types is a valid instantiation
    1.10           * of the ForAll's typevars.
    1.11           *
    1.12 @@ -1081,6 +1081,42 @@
    1.13              return types.subst(qtype, tvars, actuals);
    1.14          }
    1.15  
    1.16 +        /**
    1.17 +         * Kind of type-constraint derived during type inference
    1.18 +         */
    1.19 +        public enum ConstraintKind {
    1.20 +            /**
    1.21 +             * upper bound constraint (a type variable must be instantiated
    1.22 +             * with a type T, where T is a subtype of all the types specified by
    1.23 +             * its EXTENDS constraints).
    1.24 +             */
    1.25 +            EXTENDS,
    1.26 +            /**
    1.27 +             * lower bound constraint (a type variable must be instantiated
    1.28 +             * with a type T, where T is a supertype of all the types specified by
    1.29 +             * its SUPER constraints).
    1.30 +             */
    1.31 +            SUPER,
    1.32 +            /**
    1.33 +             * equality constraint (a type variable must be instantiated to the type
    1.34 +             * specified by its EQUAL constraint.
    1.35 +             */
    1.36 +            EQUAL;
    1.37 +        }
    1.38 +
    1.39 +        /**
    1.40 +         * Get the type-constraints of a given kind for a given type-variable of
    1.41 +         * this ForAll type. Subclasses should override in order to return more
    1.42 +         * accurate sets of constraints.
    1.43 +         *
    1.44 +         * @param tv the type-variable for which the constraint is to be retrieved
    1.45 +         * @param ck the constraint kind to be retrieved
    1.46 +         * @return the list of types specified by the selected constraint
    1.47 +         */
    1.48 +        public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
    1.49 +            return List.nil();
    1.50 +        }
    1.51 +
    1.52          public Type map(Mapping f) {
    1.53              return f.apply(qtype);
    1.54          }
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Mon Aug 31 19:43:06 2009 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Sep 01 14:53:39 2009 +0100
     2.3 @@ -29,6 +29,7 @@
     2.4  import com.sun.tools.javac.util.List;
     2.5  import com.sun.tools.javac.code.*;
     2.6  import com.sun.tools.javac.code.Type.*;
     2.7 +import com.sun.tools.javac.code.Type.ForAll.ConstraintKind;
     2.8  import com.sun.tools.javac.code.Symbol.*;
     2.9  import com.sun.tools.javac.util.JCDiagnostic;
    2.10  
    2.11 @@ -50,6 +51,7 @@
    2.12  
    2.13      Symtab syms;
    2.14      Types types;
    2.15 +    Check chk;
    2.16      Resolve rs;
    2.17      JCDiagnostic.Factory diags;
    2.18  
    2.19 @@ -65,6 +67,7 @@
    2.20          syms = Symtab.instance(context);
    2.21          types = Types.instance(context);
    2.22          rs = Resolve.instance(context);
    2.23 +        chk = Check.instance(context);
    2.24          diags = JCDiagnostic.Factory.instance(context);
    2.25          ambiguousNoInstanceException =
    2.26              new NoInstanceException(true, diags);
    2.27 @@ -250,14 +253,19 @@
    2.28                                  Warner warn) throws InferenceException {
    2.29          List<Type> undetvars = Type.map(that.tvars, fromTypeVarFun);
    2.30          for (List<Type> l = undetvars; l.nonEmpty(); l = l.tail) {
    2.31 -            UndetVar v = (UndetVar) l.head;
    2.32 +            UndetVar uv = (UndetVar) l.head;
    2.33 +            TypeVar tv = (TypeVar)uv.qtype;
    2.34              ListBuffer<Type> hibounds = new ListBuffer<Type>();
    2.35 -            for (List<Type> l1 = types.getBounds((TypeVar) v.qtype); l1.nonEmpty(); l1 = l1.tail) {
    2.36 -                if (!l1.head.containsSome(that.tvars)) {
    2.37 -                    hibounds.append(l1.head);
    2.38 +            for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS).prependList(types.getBounds(tv))) {
    2.39 +                if (!t.containsSome(that.tvars) && t.tag != BOT) {
    2.40 +                    hibounds.append(t);
    2.41                  }
    2.42              }
    2.43 -            v.hibounds = hibounds.toList();
    2.44 +            List<Type> inst = that.getConstraints(tv, ConstraintKind.EQUAL);
    2.45 +            if (inst.nonEmpty() && inst.head.tag != BOT) {
    2.46 +                uv.inst = inst.head;
    2.47 +            }
    2.48 +            uv.hibounds = hibounds.toList();
    2.49          }
    2.50          Type qtype1 = types.subst(that.qtype, that.tvars, undetvars);
    2.51          if (!types.isSubtype(qtype1, to)) {
    2.52 @@ -273,7 +281,7 @@
    2.53          List<Type> targs = Type.map(undetvars, getInstFun);
    2.54          targs = types.subst(targs, that.tvars, targs);
    2.55          checkWithinBounds(that.tvars, targs, warn);
    2.56 -        return that.inst(targs, types);
    2.57 +        return chk.checkType(warn.pos(), that.inst(targs, types), to);
    2.58      }
    2.59  
    2.60      /** Instantiate method type `mt' by finding instantiations of
    2.61 @@ -349,6 +357,9 @@
    2.62          /** Type variables instantiated to bottom */
    2.63          ListBuffer<Type> restvars = new ListBuffer<Type>();
    2.64  
    2.65 +        /** Undet vars instantiated to bottom */
    2.66 +        final ListBuffer<Type> restundet = new ListBuffer<Type>();
    2.67 +
    2.68          /** Instantiated types or TypeVars if under-constrained */
    2.69          ListBuffer<Type> insttypes = new ListBuffer<Type>();
    2.70  
    2.71 @@ -359,6 +370,7 @@
    2.72              UndetVar uv = (UndetVar)t;
    2.73              if (uv.inst.tag == BOT) {
    2.74                  restvars.append(uv.qtype);
    2.75 +                restundet.append(uv);
    2.76                  insttypes.append(uv.qtype);
    2.77                  undettypes.append(uv);
    2.78                  uv.inst = null;
    2.79 @@ -379,17 +391,32 @@
    2.80              final MethodType mt2 = new MethodType(mt.argtypes, null, mt.thrown, syms.methodClass);
    2.81              mt2.restype = new ForAll(restvars.toList(), mt.restype) {
    2.82                  @Override
    2.83 +                public List<Type> getConstraints(TypeVar tv, ConstraintKind ck) {
    2.84 +                    for (Type t : restundet.toList()) {
    2.85 +                        UndetVar uv = (UndetVar)t;
    2.86 +                        if (uv.qtype == tv) {
    2.87 +                            switch (ck) {
    2.88 +                                case EXTENDS: return uv.hibounds;
    2.89 +                                case SUPER: return uv.lobounds;
    2.90 +                                case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.<Type>nil();
    2.91 +                            }
    2.92 +                        }
    2.93 +                    }
    2.94 +                    return List.nil();
    2.95 +                }
    2.96 +
    2.97 +                @Override
    2.98                  public Type inst(List<Type> inferred, Types types) throws NoInstanceException {
    2.99                      List<Type> formals = types.subst(mt2.argtypes, tvars, inferred);
   2.100 -                   if (!rs.argumentsAcceptable(capturedArgs, formals,
   2.101 +                    if (!rs.argumentsAcceptable(capturedArgs, formals,
   2.102                             allowBoxing, useVarargs, warn)) {
   2.103                        // inferred method is not applicable
   2.104                        throw invalidInstanceException.setMessage("inferred.do.not.conform.to.params", formals, argtypes);
   2.105 -                   }
   2.106 -                   // check that inferred bounds conform to their bounds
   2.107 -                   checkWithinBounds(all_tvars,
   2.108 +                    }
   2.109 +                    // check that inferred bounds conform to their bounds
   2.110 +                    checkWithinBounds(all_tvars,
   2.111                             types.subst(inferredTypes, tvars, inferred), warn);
   2.112 -                   return super.inst(inferred, types);
   2.113 +                    return super.inst(inferred, types);
   2.114              }};
   2.115              return mt2;
   2.116          }
     3.1 --- a/test/tools/javac/generics/inference/6302954/T6476073.java	Mon Aug 31 19:43:06 2009 -0700
     3.2 +++ b/test/tools/javac/generics/inference/6302954/T6476073.java	Tue Sep 01 14:53:39 2009 +0100
     3.3 @@ -25,7 +25,6 @@
     3.4   * @test
     3.5   * @bug     6476073
     3.6   * @summary Capture using super wildcard of type variables doesn't work
     3.7 - * @ignore awaiting for 6650759 (see bug report for a detailed evaluation)
     3.8   * @compile T6476073.java
     3.9   */
    3.10  
     4.1 --- a/test/tools/javac/generics/inference/6638712/T6638712b.out	Mon Aug 31 19:43:06 2009 -0700
     4.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712b.out	Tue Sep 01 14:53:39 2009 +0100
     4.3 @@ -1,2 +1,2 @@
     4.4 -T6638712b.java:14:21: compiler.err.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.bounds: T6638712b<java.lang.Integer>, T6638712b<java.lang.String>)
     4.5 +T6638712b.java:14:21: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.no.conforming.instance.exists: T, T, java.lang.String)), <T>T, java.lang.String
     4.6  1 error
     5.1 --- a/test/tools/javac/generics/inference/6638712/T6638712e.out	Mon Aug 31 19:43:06 2009 -0700
     5.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712e.out	Tue Sep 01 14:53:39 2009 +0100
     5.3 @@ -1,2 +1,2 @@
     5.4 -T6638712e.java:17:27: compiler.err.invalid.inferred.types: X, (compiler.misc.inferred.do.not.conform.to.params: T6638712e.Foo<? super java.lang.Object,? extends java.lang.Boolean>, T6638712e.Foo<java.lang.Boolean,java.lang.Boolean>)
     5.5 +T6638712e.java:17:27: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.no.conforming.instance.exists: X, T6638712e.Foo<X,java.lang.String>, T6638712e.Foo<java.lang.Object,java.lang.String>)), <X>T6638712e.Foo<X,java.lang.String>, T6638712e.Foo<java.lang.Object,java.lang.String>
     5.6  1 error
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759a.java	Tue Sep 01 14:53:39 2009 +0100
     6.3 @@ -0,0 +1,45 @@
     6.4 +/*
     6.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.
    6.11 + *
    6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.15 + * version 2 for more details (a copy is included in the LICENSE file that
    6.16 + * accompanied this code).
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License version
    6.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.21 + *
    6.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.24 + * have any questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug     6650759
    6.30 + * @author  mcimadamore
    6.31 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
    6.32 + * @compile T6650759a.java
    6.33 + */
    6.34 +
    6.35 +class T6650759a {
    6.36 +
    6.37 +    public static interface Interface<T> { }
    6.38 +    public static class IntegerInterface implements Interface<Integer> { }
    6.39 +
    6.40 +    <I extends Interface<T>, T> T getGenericValue(I test) { return null; }
    6.41 +
    6.42 +    void testSet(Integer test) { }
    6.43 +
    6.44 +    void test() {
    6.45 +        Integer test = getGenericValue(new IntegerInterface());
    6.46 +        testSet(getGenericValue(new IntegerInterface()));
    6.47 +    }
    6.48 +}
    6.49 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759b.java	Tue Sep 01 14:53:39 2009 +0100
     7.3 @@ -0,0 +1,52 @@
     7.4 +/*
     7.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.
    7.11 + *
    7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 + * version 2 for more details (a copy is included in the LICENSE file that
    7.16 + * accompanied this code).
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License version
    7.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.21 + *
    7.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    7.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    7.24 + * have any questions.
    7.25 + */
    7.26 +
    7.27 +/*
    7.28 + * @test
    7.29 + * @bug     6650759
    7.30 + * @author  mcimadamore
    7.31 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
    7.32 + * @compile T6650759b.java
    7.33 + */
    7.34 +
    7.35 +public class T6650759b {
    7.36 +
    7.37 +    interface A<X extends A<X, Y>, Y extends B<X>> {}
    7.38 +
    7.39 +    static class B<X extends A<X, ?>> {}
    7.40 +
    7.41 +    interface C<X extends A<X, Y>, Y extends B<X>> {}
    7.42 +
    7.43 +    interface D<X extends A<X, Y>, Y extends B<X>> {}
    7.44 +
    7.45 +    static class E<X extends A<X, Y>, Y extends B<X>, W extends C<X, Y>> implements D<X, Y> {
    7.46 +
    7.47 +        static <X extends A<X, Y>, Y extends B<X>, W extends C<X, Y>> D<X, Y> of(W w) {
    7.48 +            return null;
    7.49 +        }
    7.50 +    }
    7.51 +
    7.52 +    <X extends A<X, Y>, Y extends B<X>, W extends C<X, Y>, Z extends D<X, Y>> Z test(W w) {
    7.53 +        return (Z) E.of(w);
    7.54 +    }
    7.55 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759c.java	Tue Sep 01 14:53:39 2009 +0100
     8.3 @@ -0,0 +1,49 @@
     8.4 +/*
     8.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.
    8.11 + *
    8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.15 + * version 2 for more details (a copy is included in the LICENSE file that
    8.16 + * accompanied this code).
    8.17 + *
    8.18 + * You should have received a copy of the GNU General Public License version
    8.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.21 + *
    8.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    8.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    8.24 + * have any questions.
    8.25 + */
    8.26 +
    8.27 +/*
    8.28 + * @test
    8.29 + * @bug     6650759
    8.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
    8.31 + * @compile T6650759c.java
    8.32 + */
    8.33 +
    8.34 +import java.util.Collection;
    8.35 +import java.util.Collections;
    8.36 +
    8.37 +public class T6650759c {
    8.38 +
    8.39 +  static interface A {}
    8.40 +
    8.41 +  static interface B<X extends A> {}
    8.42 +
    8.43 +  static interface C<X extends A, Y extends B<X>> {}
    8.44 +
    8.45 +  public static <T extends A, U extends B<T>> Collection<C<T,U>> get(U u) {
    8.46 +    return null;
    8.47 +  }
    8.48 +
    8.49 +  public <T extends A, U extends B<T>> Collection<C<T,U>> test(U u) {
    8.50 +    return Collections.unmodifiableCollection(get(u));
    8.51 +  }
    8.52 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759d.java	Tue Sep 01 14:53:39 2009 +0100
     9.3 @@ -0,0 +1,51 @@
     9.4 +/*
     9.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.
    9.11 + *
    9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.15 + * version 2 for more details (a copy is included in the LICENSE file that
    9.16 + * accompanied this code).
    9.17 + *
    9.18 + * You should have received a copy of the GNU General Public License version
    9.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.21 + *
    9.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    9.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    9.24 + * have any questions.
    9.25 + */
    9.26 +
    9.27 +/*
    9.28 + * @test
    9.29 + * @bug     6650759
    9.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
    9.31 + * @compile T6650759d.java
    9.32 + */
    9.33 +
    9.34 +public class T6650759d {
    9.35 +
    9.36 +    static abstract class A<X> {
    9.37 +
    9.38 +        static <T> A<T> m(Iterable<? extends T> elements) {
    9.39 +            return null;
    9.40 +        }
    9.41 +    }
    9.42 +
    9.43 +    static abstract class B {}
    9.44 +
    9.45 +    static abstract class C<X extends B> {}
    9.46 +
    9.47 +    <U extends C<V>, V extends B> Iterable<V> get(U u) {
    9.48 +        return null;
    9.49 +    }
    9.50 +
    9.51 +    <U extends C<V>, V extends B> void m(U u) {
    9.52 +        A<V> a = A.m(get(u));
    9.53 +    }
    9.54 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759e.java	Tue Sep 01 14:53:39 2009 +0100
    10.3 @@ -0,0 +1,52 @@
    10.4 +/*
    10.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.
   10.11 + *
   10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.15 + * version 2 for more details (a copy is included in the LICENSE file that
   10.16 + * accompanied this code).
   10.17 + *
   10.18 + * You should have received a copy of the GNU General Public License version
   10.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.21 + *
   10.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   10.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   10.24 + * have any questions.
   10.25 + */
   10.26 +
   10.27 +/*
   10.28 + * @test
   10.29 + * @bug     6650759
   10.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   10.31 + * @compile T6650759e.java
   10.32 + */
   10.33 +
   10.34 +import java.util.List;
   10.35 +
   10.36 +public class T6650759e {
   10.37 +
   10.38 +    static abstract class A<X extends B> {}
   10.39 +
   10.40 +    interface B<X extends A> extends D {}
   10.41 +
   10.42 +    static abstract class C<X extends D> {}
   10.43 +
   10.44 +    interface D {}
   10.45 +
   10.46 +    static abstract class E<X extends C<? extends B<?>>> {}
   10.47 +
   10.48 +    <U extends C<V>, V extends B<W>, W extends A<V>> W m1(E<U> e) {
   10.49 +        return m2(e);
   10.50 +    }
   10.51 +
   10.52 +    <U extends C<V>, V extends B<W>, W extends A<V>> W m2(E<U> e) {
   10.53 +        return null;
   10.54 +    }
   10.55 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759f.java	Tue Sep 01 14:53:39 2009 +0100
    11.3 @@ -0,0 +1,50 @@
    11.4 +/*
    11.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.
   11.11 + *
   11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.15 + * version 2 for more details (a copy is included in the LICENSE file that
   11.16 + * accompanied this code).
   11.17 + *
   11.18 + * You should have received a copy of the GNU General Public License version
   11.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.21 + *
   11.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   11.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   11.24 + * have any questions.
   11.25 + */
   11.26 +
   11.27 +/*
   11.28 + * @test
   11.29 + * @bug     6650759
   11.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   11.31 + * @compile T6650759f.java
   11.32 + */
   11.33 +
   11.34 +import java.util.Collections;
   11.35 +
   11.36 +public class T6650759f {
   11.37 +
   11.38 +    interface A<X extends A> {}
   11.39 +
   11.40 +    static abstract class B<X extends B> implements A<X> {}
   11.41 +
   11.42 +    static abstract class C<X extends D> extends B<X> {}
   11.43 +
   11.44 +    static class D extends C<D> {}
   11.45 +
   11.46 +    <X extends B, Y extends B<X>> Iterable<X> m(Y node) {
   11.47 +        return null;
   11.48 +    }
   11.49 +
   11.50 +    public void test(D d) {
   11.51 +        Iterable<D> ops = (true) ? Collections.singletonList(d) : m(d);
   11.52 +    }
   11.53 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759g.java	Tue Sep 01 14:53:39 2009 +0100
    12.3 @@ -0,0 +1,59 @@
    12.4 +/*
    12.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.
   12.11 + *
   12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 + * version 2 for more details (a copy is included in the LICENSE file that
   12.16 + * accompanied this code).
   12.17 + *
   12.18 + * You should have received a copy of the GNU General Public License version
   12.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.21 + *
   12.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   12.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   12.24 + * have any questions.
   12.25 + */
   12.26 +
   12.27 +/*
   12.28 + * @test
   12.29 + * @bug     6650759
   12.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   12.31 + * @compile T6650759g.java
   12.32 + */
   12.33 +
   12.34 +public class T6650759g {
   12.35 +
   12.36 +    static abstract class A<X extends A<X>> {}
   12.37 +
   12.38 +    static abstract class B<X extends A<X>> {}
   12.39 +
   12.40 +    interface C<X, Y> {}
   12.41 +
   12.42 +    static abstract class D<X extends A<X>, Y extends B<X>> implements C<X, Y> {}
   12.43 +
   12.44 +    static class E extends A<E> {}
   12.45 +
   12.46 +    static class F extends B<E> {}
   12.47 +
   12.48 +    static void test(Iterable<E> data) {
   12.49 +        m3(m2(data, m1(F.class)));
   12.50 +    }
   12.51 +
   12.52 +    static <X extends A<X>, Y extends B<X>> D<X, Y> m1(Class<Y> c) {
   12.53 +        return null;
   12.54 +    }
   12.55 +
   12.56 +    static <U, V> Iterable<V> m2(Iterable<U> x1, C<? super U, ? extends V> x2) {
   12.57 +        return null;
   12.58 +    }
   12.59 +
   12.60 +    static void m3(Iterable<F> data) {
   12.61 +    }
   12.62 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759h.java	Tue Sep 01 14:53:39 2009 +0100
    13.3 @@ -0,0 +1,39 @@
    13.4 +/*
    13.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   13.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   13.24 + * have any questions.
   13.25 + */
   13.26 +
   13.27 +/*
   13.28 + * @test
   13.29 + * @bug     6650759
   13.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   13.31 + * @compile T6650759h.java
   13.32 + */
   13.33 +class T6650759h<X, Y> {
   13.34 +
   13.35 +    <A> Object m(A a, T6650759h<?, ? super A> t) {
   13.36 +        return null;
   13.37 +    }
   13.38 +
   13.39 +    void test(T6650759h<?, Void> t) {
   13.40 +        m(null, t);
   13.41 +    }
   13.42 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759i.java	Tue Sep 01 14:53:39 2009 +0100
    14.3 @@ -0,0 +1,54 @@
    14.4 +/*
    14.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.7 + *
    14.8 + * This code is free software; you can redistribute it and/or modify it
    14.9 + * under the terms of the GNU General Public License version 2 only, as
   14.10 + * published by the Free Software Foundation.
   14.11 + *
   14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14.15 + * version 2 for more details (a copy is included in the LICENSE file that
   14.16 + * accompanied this code).
   14.17 + *
   14.18 + * You should have received a copy of the GNU General Public License version
   14.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   14.21 + *
   14.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   14.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   14.24 + * have any questions.
   14.25 + */
   14.26 +
   14.27 +/*
   14.28 + * @test
   14.29 + * @bug     6650759
   14.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   14.31 + * @compile T6650759i.java
   14.32 + */
   14.33 +public class T6650759i {
   14.34 +
   14.35 +    static class A<X extends A, Y extends B> {}
   14.36 +
   14.37 +    static class B<X extends B> {}
   14.38 +
   14.39 +    static class C<X extends A<X, Y>, Y extends B<Y>> {}
   14.40 +
   14.41 +    static <U extends A<U, V>, V extends B<V>> Class<U> m1(U x) {
   14.42 +        return null;
   14.43 +    }
   14.44 +
   14.45 +    static <U extends A<U, V>, V extends B<V>> U m2(Class<U> c) {
   14.46 +        return null;
   14.47 +    }
   14.48 +
   14.49 +    static <W, U extends A<U, V>, V extends B<V>> W m3(Class<W> c1, C<U, V> c2) {
   14.50 +        return null;
   14.51 +    }
   14.52 +
   14.53 +    static <U extends A<U, V>, V extends B<V>> void test(U u, C<U, V> c) {
   14.54 +        m2(m1(u));
   14.55 +        U res = m3(m1(u), c);
   14.56 +    }
   14.57 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759j.java	Tue Sep 01 14:53:39 2009 +0100
    15.3 @@ -0,0 +1,54 @@
    15.4 +/*
    15.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + *
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.
   15.11 + *
   15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.15 + * version 2 for more details (a copy is included in the LICENSE file that
   15.16 + * accompanied this code).
   15.17 + *
   15.18 + * You should have received a copy of the GNU General Public License version
   15.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.21 + *
   15.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   15.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   15.24 + * have any questions.
   15.25 + */
   15.26 +
   15.27 +/*
   15.28 + * @test
   15.29 + * @bug     6650759
   15.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   15.31 + * @compile T6650759j.java
   15.32 + */
   15.33 +
   15.34 +public class T6650759j {
   15.35 +
   15.36 +    static abstract class A<X extends A<X>> {}
   15.37 +
   15.38 +    static abstract class B<X extends B<X, Y>, Y> extends A<X> {}
   15.39 +
   15.40 +    static abstract class C<X extends C<X, Y>, Y> extends B<X, Y> {}
   15.41 +
   15.42 +    interface D {}
   15.43 +
   15.44 +    static class E extends C<E, D> {}
   15.45 +
   15.46 +    static abstract class F<X extends F<X, Y>, Y extends A<Y>> extends A<X> {}
   15.47 +
   15.48 +    static class G extends F<G, E> {}
   15.49 +
   15.50 +    static <X extends F<X, Y>, Y extends A<Y>> X m(Iterable<X> it) {
   15.51 +        return null;
   15.52 +    }
   15.53 +
   15.54 +    static G test(Iterable<G> c) {
   15.55 +        return m(c);
   15.56 +    }
   15.57 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759k.java	Tue Sep 01 14:53:39 2009 +0100
    16.3 @@ -0,0 +1,44 @@
    16.4 +/*
    16.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + *
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.
   16.11 + *
   16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.15 + * version 2 for more details (a copy is included in the LICENSE file that
   16.16 + * accompanied this code).
   16.17 + *
   16.18 + * You should have received a copy of the GNU General Public License version
   16.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.21 + *
   16.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   16.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   16.24 + * have any questions.
   16.25 + */
   16.26 +
   16.27 +/*
   16.28 + * @test
   16.29 + * @bug     6650759
   16.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   16.31 + * @compile T6650759k.java
   16.32 + */
   16.33 +
   16.34 +public class T6650759k {
   16.35 +
   16.36 +    static class A<X extends A> {}
   16.37 +
   16.38 +    static class B<X extends B, Y extends A> {}
   16.39 +
   16.40 +    <U extends A<U>, V extends B<V, U>> Object m(Class<V> c) {
   16.41 +        return null;
   16.42 +    }
   16.43 +
   16.44 +    <U extends A<U>, V extends B<V, U>> void test(Class<V> c) {
   16.45 +        m(c);
   16.46 +    }
   16.47 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759l.java	Tue Sep 01 14:53:39 2009 +0100
    17.3 @@ -0,0 +1,46 @@
    17.4 +/*
    17.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.
   17.11 + *
   17.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.15 + * version 2 for more details (a copy is included in the LICENSE file that
   17.16 + * accompanied this code).
   17.17 + *
   17.18 + * You should have received a copy of the GNU General Public License version
   17.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.21 + *
   17.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   17.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   17.24 + * have any questions.
   17.25 + */
   17.26 +
   17.27 +/*
   17.28 + * @test
   17.29 + * @bug     6650759
   17.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   17.31 + * @compile T6650759l.java
   17.32 + */
   17.33 +
   17.34 +public class T6650759l {
   17.35 +
   17.36 +    public static interface A<X> {}
   17.37 +
   17.38 +    public static class B implements A<Integer> {}
   17.39 +
   17.40 +    public static <X extends A<Y>, Y> Y m1(X x) {
   17.41 +        return null;
   17.42 +    }
   17.43 +
   17.44 +    public static void m2(Integer i) {}
   17.45 +
   17.46 +    public static void test(B b) {
   17.47 +        m2(m1(b));
   17.48 +    }
   17.49 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759m.java	Tue Sep 01 14:53:39 2009 +0100
    18.3 @@ -0,0 +1,47 @@
    18.4 +/*
    18.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + *
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.
   18.11 + *
   18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.15 + * version 2 for more details (a copy is included in the LICENSE file that
   18.16 + * accompanied this code).
   18.17 + *
   18.18 + * You should have received a copy of the GNU General Public License version
   18.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.21 + *
   18.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   18.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   18.24 + * have any questions.
   18.25 + */
   18.26 +
   18.27 +/*
   18.28 + * @test
   18.29 + * @bug     6650759
   18.30 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed
   18.31 + * @compile/fail/ref=T6650759m.out T6650759m.java -XDrawDiagnostics
   18.32 + */
   18.33 +
   18.34 +import java.util.*;
   18.35 +
   18.36 +class T6650759m {
   18.37 +    <Z> List<? super Z> m(List<? extends List<? super Z>> ls) {
   18.38 +        return ls.get(0);
   18.39 +    }
   18.40 +
   18.41 +    void test() {
   18.42 +        ArrayList<ArrayList<Integer>> lli = new ArrayList<ArrayList<Integer>>();
   18.43 +        ArrayList<Integer> li = new ArrayList<Integer>();
   18.44 +        li.add(2);
   18.45 +        lli.add(li);
   18.46 +        List<? super String> ls = m(lli); //here
   18.47 +        ls.add("crash");
   18.48 +        Integer i = li.get(1);
   18.49 +    }
   18.50 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/test/tools/javac/generics/inference/6650759/T6650759m.out	Tue Sep 01 14:53:39 2009 +0100
    19.3 @@ -0,0 +1,2 @@
    19.4 +T6650759m.java:43:36: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.util.List<? super java.lang.Integer>, java.util.List<? super java.lang.String>
    19.5 +1 error

mercurial