# HG changeset patch # User mcimadamore # Date 1251813219 -3600 # Node ID 38a70273507bdd57c2f76cc1086b12305d6860ae # Parent 9d8c7669df64ce4fa59f9a43a15afd3094996674 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 diff -r 9d8c7669df64 -r 38a70273507b langtools/src/share/classes/com/sun/tools/javac/code/Type.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Type.java Mon Aug 31 19:43:06 2009 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Type.java Tue Sep 01 14:53:39 2009 +0100 @@ -1068,7 +1068,7 @@ /** * Replaces this ForAll's typevars with a set of concrete Java types - * and returns the instantiated generic type. Subclasses might override + * and returns the instantiated generic type. Subclasses should override * in order to check that the list of types is a valid instantiation * of the ForAll's typevars. * @@ -1081,6 +1081,42 @@ return types.subst(qtype, tvars, actuals); } + /** + * Kind of type-constraint derived during type inference + */ + public enum ConstraintKind { + /** + * upper bound constraint (a type variable must be instantiated + * with a type T, where T is a subtype of all the types specified by + * its EXTENDS constraints). + */ + EXTENDS, + /** + * lower bound constraint (a type variable must be instantiated + * with a type T, where T is a supertype of all the types specified by + * its SUPER constraints). + */ + SUPER, + /** + * equality constraint (a type variable must be instantiated to the type + * specified by its EQUAL constraint. + */ + EQUAL; + } + + /** + * Get the type-constraints of a given kind for a given type-variable of + * this ForAll type. Subclasses should override in order to return more + * accurate sets of constraints. + * + * @param tv the type-variable for which the constraint is to be retrieved + * @param ck the constraint kind to be retrieved + * @return the list of types specified by the selected constraint + */ + public List getConstraints(TypeVar tv, ConstraintKind ck) { + return List.nil(); + } + public Type map(Mapping f) { return f.apply(qtype); } diff -r 9d8c7669df64 -r 38a70273507b langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Aug 31 19:43:06 2009 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Sep 01 14:53:39 2009 +0100 @@ -29,6 +29,7 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Type.*; +import com.sun.tools.javac.code.Type.ForAll.ConstraintKind; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.util.JCDiagnostic; @@ -50,6 +51,7 @@ Symtab syms; Types types; + Check chk; Resolve rs; JCDiagnostic.Factory diags; @@ -65,6 +67,7 @@ syms = Symtab.instance(context); types = Types.instance(context); rs = Resolve.instance(context); + chk = Check.instance(context); diags = JCDiagnostic.Factory.instance(context); ambiguousNoInstanceException = new NoInstanceException(true, diags); @@ -250,14 +253,19 @@ Warner warn) throws InferenceException { List undetvars = Type.map(that.tvars, fromTypeVarFun); for (List l = undetvars; l.nonEmpty(); l = l.tail) { - UndetVar v = (UndetVar) l.head; + UndetVar uv = (UndetVar) l.head; + TypeVar tv = (TypeVar)uv.qtype; ListBuffer hibounds = new ListBuffer(); - for (List l1 = types.getBounds((TypeVar) v.qtype); l1.nonEmpty(); l1 = l1.tail) { - if (!l1.head.containsSome(that.tvars)) { - hibounds.append(l1.head); + for (Type t : that.getConstraints(tv, ConstraintKind.EXTENDS).prependList(types.getBounds(tv))) { + if (!t.containsSome(that.tvars) && t.tag != BOT) { + hibounds.append(t); } } - v.hibounds = hibounds.toList(); + List inst = that.getConstraints(tv, ConstraintKind.EQUAL); + if (inst.nonEmpty() && inst.head.tag != BOT) { + uv.inst = inst.head; + } + uv.hibounds = hibounds.toList(); } Type qtype1 = types.subst(that.qtype, that.tvars, undetvars); if (!types.isSubtype(qtype1, to)) { @@ -273,7 +281,7 @@ List targs = Type.map(undetvars, getInstFun); targs = types.subst(targs, that.tvars, targs); checkWithinBounds(that.tvars, targs, warn); - return that.inst(targs, types); + return chk.checkType(warn.pos(), that.inst(targs, types), to); } /** Instantiate method type `mt' by finding instantiations of @@ -349,6 +357,9 @@ /** Type variables instantiated to bottom */ ListBuffer restvars = new ListBuffer(); + /** Undet vars instantiated to bottom */ + final ListBuffer restundet = new ListBuffer(); + /** Instantiated types or TypeVars if under-constrained */ ListBuffer insttypes = new ListBuffer(); @@ -359,6 +370,7 @@ UndetVar uv = (UndetVar)t; if (uv.inst.tag == BOT) { restvars.append(uv.qtype); + restundet.append(uv); insttypes.append(uv.qtype); undettypes.append(uv); uv.inst = null; @@ -379,17 +391,32 @@ final MethodType mt2 = new MethodType(mt.argtypes, null, mt.thrown, syms.methodClass); mt2.restype = new ForAll(restvars.toList(), mt.restype) { @Override + public List getConstraints(TypeVar tv, ConstraintKind ck) { + for (Type t : restundet.toList()) { + UndetVar uv = (UndetVar)t; + if (uv.qtype == tv) { + switch (ck) { + case EXTENDS: return uv.hibounds; + case SUPER: return uv.lobounds; + case EQUAL: return uv.inst != null ? List.of(uv.inst) : List.nil(); + } + } + } + return List.nil(); + } + + @Override public Type inst(List inferred, Types types) throws NoInstanceException { List formals = types.subst(mt2.argtypes, tvars, inferred); - if (!rs.argumentsAcceptable(capturedArgs, formals, + if (!rs.argumentsAcceptable(capturedArgs, formals, allowBoxing, useVarargs, warn)) { // inferred method is not applicable throw invalidInstanceException.setMessage("inferred.do.not.conform.to.params", formals, argtypes); - } - // check that inferred bounds conform to their bounds - checkWithinBounds(all_tvars, + } + // check that inferred bounds conform to their bounds + checkWithinBounds(all_tvars, types.subst(inferredTypes, tvars, inferred), warn); - return super.inst(inferred, types); + return super.inst(inferred, types); }}; return mt2; } diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6302954/T6476073.java --- a/langtools/test/tools/javac/generics/inference/6302954/T6476073.java Mon Aug 31 19:43:06 2009 -0700 +++ b/langtools/test/tools/javac/generics/inference/6302954/T6476073.java Tue Sep 01 14:53:39 2009 +0100 @@ -25,7 +25,6 @@ * @test * @bug 6476073 * @summary Capture using super wildcard of type variables doesn't work - * @ignore awaiting for 6650759 (see bug report for a detailed evaluation) * @compile T6476073.java */ diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6638712/T6638712b.out --- a/langtools/test/tools/javac/generics/inference/6638712/T6638712b.out Mon Aug 31 19:43:06 2009 -0700 +++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712b.out Tue Sep 01 14:53:39 2009 +0100 @@ -1,2 +1,2 @@ -T6638712b.java:14:21: compiler.err.invalid.inferred.types: T, (compiler.misc.inferred.do.not.conform.to.bounds: T6638712b, T6638712b) +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, java.lang.String 1 error diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6638712/T6638712e.out --- a/langtools/test/tools/javac/generics/inference/6638712/T6638712e.out Mon Aug 31 19:43:06 2009 -0700 +++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712e.out Tue Sep 01 14:53:39 2009 +0100 @@ -1,2 +1,2 @@ -T6638712e.java:17:27: compiler.err.invalid.inferred.types: X, (compiler.misc.inferred.do.not.conform.to.params: T6638712e.Foo, T6638712e.Foo) +T6638712e.java:17:27: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.no.conforming.instance.exists: X, T6638712e.Foo, T6638712e.Foo)), T6638712e.Foo, T6638712e.Foo 1 error diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759a.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @author mcimadamore + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759a.java + */ + +class T6650759a { + + public static interface Interface { } + public static class IntegerInterface implements Interface { } + + , T> T getGenericValue(I test) { return null; } + + void testSet(Integer test) { } + + void test() { + Integer test = getGenericValue(new IntegerInterface()); + testSet(getGenericValue(new IntegerInterface())); + } +} \ No newline at end of file diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759b.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @author mcimadamore + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759b.java + */ + +public class T6650759b { + + interface A, Y extends B> {} + + static class B> {} + + interface C, Y extends B> {} + + interface D, Y extends B> {} + + static class E, Y extends B, W extends C> implements D { + + static , Y extends B, W extends C> D of(W w) { + return null; + } + } + + , Y extends B, W extends C, Z extends D> Z test(W w) { + return (Z) E.of(w); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759c.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759c.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759c.java + */ + +import java.util.Collection; +import java.util.Collections; + +public class T6650759c { + + static interface A {} + + static interface B {} + + static interface C> {} + + public static > Collection> get(U u) { + return null; + } + + public > Collection> test(U u) { + return Collections.unmodifiableCollection(get(u)); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759d.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759d.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759d.java + */ + +public class T6650759d { + + static abstract class A { + + static A m(Iterable elements) { + return null; + } + } + + static abstract class B {} + + static abstract class C {} + + , V extends B> Iterable get(U u) { + return null; + } + + , V extends B> void m(U u) { + A a = A.m(get(u)); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759e.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759e.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759e.java + */ + +import java.util.List; + +public class T6650759e { + + static abstract class A {} + + interface B extends D {} + + static abstract class C {} + + interface D {} + + static abstract class E>> {} + + , V extends B, W extends A> W m1(E e) { + return m2(e); + } + + , V extends B, W extends A> W m2(E e) { + return null; + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759f.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759f.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759f.java + */ + +import java.util.Collections; + +public class T6650759f { + + interface A {} + + static abstract class B implements A {} + + static abstract class C extends B {} + + static class D extends C {} + + > Iterable m(Y node) { + return null; + } + + public void test(D d) { + Iterable ops = (true) ? Collections.singletonList(d) : m(d); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759g.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759g.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,59 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759g.java + */ + +public class T6650759g { + + static abstract class A> {} + + static abstract class B> {} + + interface C {} + + static abstract class D, Y extends B> implements C {} + + static class E extends A {} + + static class F extends B {} + + static void test(Iterable data) { + m3(m2(data, m1(F.class))); + } + + static , Y extends B> D m1(Class c) { + return null; + } + + static Iterable m2(Iterable x1, C x2) { + return null; + } + + static void m3(Iterable data) { + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759h.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759h.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759h.java + */ +class T6650759h { + + Object m(A a, T6650759h t) { + return null; + } + + void test(T6650759h t) { + m(null, t); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759i.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759i.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,54 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759i.java + */ +public class T6650759i { + + static class A {} + + static class B {} + + static class C, Y extends B> {} + + static , V extends B> Class m1(U x) { + return null; + } + + static , V extends B> U m2(Class c) { + return null; + } + + static , V extends B> W m3(Class c1, C c2) { + return null; + } + + static , V extends B> void test(U u, C c) { + m2(m1(u)); + U res = m3(m1(u), c); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759j.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759j.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,54 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759j.java + */ + +public class T6650759j { + + static abstract class A> {} + + static abstract class B, Y> extends A {} + + static abstract class C, Y> extends B {} + + interface D {} + + static class E extends C {} + + static abstract class F, Y extends A> extends A {} + + static class G extends F {} + + static , Y extends A> X m(Iterable it) { + return null; + } + + static G test(Iterable c) { + return m(c); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759k.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759k.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759k.java + */ + +public class T6650759k { + + static class A {} + + static class B {} + + , V extends B> Object m(Class c) { + return null; + } + + , V extends B> void test(Class c) { + m(c); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759l.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759l.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile T6650759l.java + */ + +public class T6650759l { + + public static interface A {} + + public static class B implements A {} + + public static , Y> Y m1(X x) { + return null; + } + + public static void m2(Integer i) {} + + public static void test(B b) { + m2(m1(b)); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759m.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759m.java Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,47 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6650759 + * @summary Inference of formal type parameter (unused in formal parameters) is not performed + * @compile/fail/ref=T6650759m.out T6650759m.java -XDrawDiagnostics + */ + +import java.util.*; + +class T6650759m { + List m(List> ls) { + return ls.get(0); + } + + void test() { + ArrayList> lli = new ArrayList>(); + ArrayList li = new ArrayList(); + li.add(2); + lli.add(li); + List ls = m(lli); //here + ls.add("crash"); + Integer i = li.get(1); + } +} diff -r 9d8c7669df64 -r 38a70273507b langtools/test/tools/javac/generics/inference/6650759/T6650759m.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/inference/6650759/T6650759m.out Tue Sep 01 14:53:39 2009 +0100 @@ -0,0 +1,2 @@ +T6650759m.java:43:36: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.util.List, java.util.List +1 error