7086586: Inference producing null type argument

Fri, 16 Sep 2011 14:16:11 +0100

author
mcimadamore
date
Fri, 16 Sep 2011 14:16:11 +0100
changeset 1093
c0835c8489b0
parent 1092
826ae6a2f27d
child 1094
dea82aa3ca4f

7086586: Inference producing null type argument
Summary: Inference should fail in 15.12.2.7 when inference variables with 'nulltype' upper bounds are found
Reviewed-by: dlsmith

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6862608/T6862608a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/6638712/T6638712a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/7086586/T7086586.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/7086586/T7086586.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/inference/7086586/T7086586b.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Sep 14 18:26:57 2011 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Sep 16 14:16:11 2011 +0100
     1.3 @@ -508,8 +508,13 @@
     1.4              @Override
     1.5              public Boolean visitUndetVar(UndetVar t, Type s) {
     1.6                  //todo: test against origin needed? or replace with substitution?
     1.7 -                if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
     1.8 +                if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) {
     1.9                      return true;
    1.10 +                } else if (s.tag == BOT) {
    1.11 +                    //if 's' is 'null' there's no instantiated type U for which
    1.12 +                    //U <: s (but 'null' itself, which is not a valid type)
    1.13 +                    return false;
    1.14 +                }
    1.15  
    1.16                  if (t.inst != null)
    1.17                      return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
     2.1 --- a/test/tools/javac/Diagnostics/6862608/T6862608a.out	Wed Sep 14 18:26:57 2011 -0700
     2.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.out	Fri Sep 16 14:16:11 2011 +0100
     2.3 @@ -1,3 +1,3 @@
     2.4 -T6862608a.java:19:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String>
     2.5 +T6862608a.java:19:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)
     2.6  - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))}
     2.7  1 error
     3.1 --- a/test/tools/javac/generics/inference/6638712/T6638712a.out	Wed Sep 14 18:26:57 2011 -0700
     3.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712a.out	Fri Sep 16 14:16:11 2011 +0100
     3.3 @@ -1,2 +1,2 @@
     3.4 -T6638712a.java:16:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String>
     3.5 +T6638712a.java:16:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>)
     3.6  1 error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586.java	Fri Sep 16 14:16:11 2011 +0100
     4.3 @@ -0,0 +1,19 @@
     4.4 +/**
     4.5 + * @test /nodynamiccopyright/
     4.6 + * @bug 7086586
     4.7 + * @summary Inference producing null type argument
     4.8 + * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java
     4.9 + */
    4.10 +import java.util.List;
    4.11 +
    4.12 +class T7086586 {
    4.13 +
    4.14 +    <T> List<T> m(List<? super T> dummy) { return null; }
    4.15 +
    4.16 +    void test(List<?> l) {
    4.17 +        String s = m(l).get(0);
    4.18 +        Number n = m(l).get(0);
    4.19 +        Exception e = m(l).get(0);
    4.20 +        m(l).nonExistentMethod();
    4.21 +    }
    4.22 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out	Fri Sep 16 14:16:11 2011 +0100
     5.3 @@ -0,0 +1,5 @@
     5.4 +T7086586.java:14:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)
     5.5 +T7086586.java:15:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)
     5.6 +T7086586.java:16:23: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)
     5.7 +T7086586.java:17:9: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>)
     5.8 +4 errors
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586b.java	Fri Sep 16 14:16:11 2011 +0100
     6.3 @@ -0,0 +1,54 @@
     6.4 +/*
     6.5 + * Copyright (c) 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.23 + * or visit www.oracle.com if you need additional information or have any
    6.24 + * questions.
    6.25 + */
    6.26 +
    6.27 +/*
    6.28 + * @test
    6.29 + * @bug 7086586
    6.30 + *
    6.31 + * @summary Inference producing null type argument
    6.32 + */
    6.33 +import java.util.List;
    6.34 +
    6.35 +public class T7086586b {
    6.36 +
    6.37 +    int assertionCount = 0;
    6.38 +
    6.39 +    void assertTrue(boolean cond) {
    6.40 +        if (!cond) {
    6.41 +            throw new AssertionError();
    6.42 +        }
    6.43 +        assertionCount++;
    6.44 +    }
    6.45 +
    6.46 +    <T> void m(List<? super T> dummy) { assertTrue(false); }
    6.47 +    <T> void m(Object dummy) { assertTrue(true); }
    6.48 +
    6.49 +    void test(List<?> l) {
    6.50 +        m(l);
    6.51 +        assertTrue(assertionCount == 1);
    6.52 +    }
    6.53 +
    6.54 +    public static void main(String[] args) {
    6.55 +        new T7086586b().test(null);
    6.56 +    }
    6.57 +}

mercurial