From 1ad615d16fa1078c1acef3fd0748e088590c8cb3 Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Fri, 22 Mar 2013 12:43:09 +0000 Subject: [PATCH] 8010303: Graph inference: missing incorporation step causes spurious inference error Summary: Multiple equality constraints on inference vars are not used to generate new inference constraints Reviewed-by: jjg --- .../com/sun/tools/javac/code/Types.java | 11 ++++ .../com/sun/tools/javac/comp/Infer.java | 32 +++++----- test/tools/javac/lambda/TargetType28.out | 2 +- test/tools/javac/lambda/TargetType67.java | 50 +++++++++++++++ test/tools/javac/lambda/TargetType68.java | 63 +++++++++++++++++++ test/tools/javac/lambda/TargetType69.java | 51 +++++++++++++++ 6 files changed, 194 insertions(+), 15 deletions(-) create mode 100644 test/tools/javac/lambda/TargetType67.java create mode 100644 test/tools/javac/lambda/TargetType68.java create mode 100644 test/tools/javac/lambda/TargetType69.java diff --git a/src/share/classes/com/sun/tools/javac/code/Types.java b/src/share/classes/com/sun/tools/javac/code/Types.java index 03bdaa17..a99a775a 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -1178,6 +1178,17 @@ public class Types { protected boolean containsTypes(List ts1, List ts2) { return isSameTypes(ts1, ts2, true); } + + @Override + public Boolean visitWildcardType(WildcardType t, Type s) { + if (!s.hasTag(WILDCARD)) { + return false; + } else { + WildcardType t2 = (WildcardType)s; + return t.kind == t2.kind && + isSameType(t.type, t2.type, true); + } + } }; // diff --git a/src/share/classes/com/sun/tools/javac/comp/Infer.java b/src/share/classes/com/sun/tools/javac/comp/Infer.java index 296b50d9..55d0b195 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java @@ -585,11 +585,7 @@ public class Infer { Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { - if (!inferenceContext.inferenceVars().contains(b1) && - !inferenceContext.inferenceVars().contains(b2) && - infer.types.asSuper(b2, b1.tsym) != null) { - infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); - } + infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); } } } @@ -603,11 +599,7 @@ public class Infer { Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { for (Type b2 : uv.getBounds(InferenceBound.EQ)) { - if (!inferenceContext.inferenceVars().contains(b1) && - !inferenceContext.inferenceVars().contains(b2) && - infer.types.asSuper(b2, b1.tsym) != null) { - infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); - } + infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); } } } @@ -621,10 +613,22 @@ public class Infer { Infer infer = inferenceContext.infer(); for (Type b1 : uv.getBounds(InferenceBound.EQ)) { for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { - if (!inferenceContext.inferenceVars().contains(b1) && - !inferenceContext.inferenceVars().contains(b2) && - infer.types.asSuper(b2, b1.tsym) != null) { - infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); + infer.types.isSubtypeUnchecked(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); + } + } + } + }, + /** + * Given a bound set containing {@code alpha == S} and {@code alpha == T} + * perform {@code S == T} (which could lead to new bounds). + */ + CROSS_EQ_EQ() { + public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { + Infer infer = inferenceContext.infer(); + for (Type b1 : uv.getBounds(InferenceBound.EQ)) { + for (Type b2 : uv.getBounds(InferenceBound.EQ)) { + if (b1 != b2) { + infer.types.isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1)); } } } diff --git a/test/tools/javac/lambda/TargetType28.out b/test/tools/javac/lambda/TargetType28.out index bb0c8a0d..57a38f35 100644 --- a/test/tools/javac/lambda/TargetType28.out +++ b/test/tools/javac/lambda/TargetType28.out @@ -1,2 +1,2 @@ -TargetType28.java:20:32: compiler.err.prob.found.req: (compiler.misc.incompatible.eq.upper.bounds: X, java.lang.String,R, java.lang.Object,java.lang.Number) +TargetType28.java:20:32: compiler.err.prob.found.req: (compiler.misc.incompatible.eq.upper.bounds: X, R,java.lang.String, java.lang.Object,java.lang.Number) 1 error diff --git a/test/tools/javac/lambda/TargetType67.java b/test/tools/javac/lambda/TargetType67.java new file mode 100644 index 00000000..b949b32c --- /dev/null +++ b/test/tools/javac/lambda/TargetType67.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8010303 + * @summary Graph inference: missing incorporation step causes spurious inference error + * @compile TargetType67.java + */ +class TargetType67 { + + interface Func { + B f(A a); + } + + class List { + + List map(Func f) { + return null; + } + + List apply(final List> lf) { + return null; + } + + List bind(final List lb, final Func> f) { + return lb.apply(map(f)); + } + } +} diff --git a/test/tools/javac/lambda/TargetType68.java b/test/tools/javac/lambda/TargetType68.java new file mode 100644 index 00000000..92ce99bd --- /dev/null +++ b/test/tools/javac/lambda/TargetType68.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8010303 + * @summary Graph inference: missing incorporation step causes spurious inference error + * @compile TargetType68.java + */ +import java.util.*; + +class TargetType68 { + + //derived from FX 2.2 API + static class XYChart { + static final class Series { + Series(java.lang.String name, ObservableList> data) { } + } + + static final class Data { } + + ObservableList> getData() { return null; } + } + + //derived from FX 2.2 API + interface ObservableList extends List { + boolean setAll(Collection col); + } + + //derived from FX 2.2 API + static class FXCollections { + static ObservableList observableList(List l) { return null; } + } + + private void testMethod() { + XYChart numberChart = null; + List> data_1 = new ArrayList<>(); + List> data_2 = new ArrayList<>(); + numberChart.getData().setAll( + Arrays.asList(new XYChart.Series<>("Data", FXCollections.observableList(data_1)), + new XYChart.Series<>("Data", FXCollections.observableList(data_2)))); + } +} diff --git a/test/tools/javac/lambda/TargetType69.java b/test/tools/javac/lambda/TargetType69.java new file mode 100644 index 00000000..0b47bb09 --- /dev/null +++ b/test/tools/javac/lambda/TargetType69.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8010303 + * @summary Graph inference: missing incorporation step causes spurious inference error + * @compile TargetType68.java + */ +import java.util.*; + +class TargetType68 { + + interface Function { + Y m(X x); + } + + abstract class TabulationAssertion { } + + class GroupedMapAssertion> extends TabulationAssertion { + GroupedMapAssertion(Function classifier) { } + } + + + void exerciseMapTabulation(Function collector, + TabulationAssertion assertion) { } + + void test(Function classifier, Function>> coll) { + exerciseMapTabulation(coll, new GroupedMapAssertion<>(classifier)); + } +} -- GitLab