mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-01 05:58:29 +00:00
7086586: Inference producing null type argument
Inference should fail in 15.12.2.7 when inference variables with 'nulltype' upper bounds are found Reviewed-by: dlsmith
This commit is contained in:
parent
4589920917
commit
bd420dc94e
@ -508,8 +508,13 @@ public class Types {
|
||||
@Override
|
||||
public Boolean visitUndetVar(UndetVar t, Type s) {
|
||||
//todo: test against origin needed? or replace with substitution?
|
||||
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
|
||||
if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) {
|
||||
return true;
|
||||
} else if (s.tag == BOT) {
|
||||
//if 's' is 'null' there's no instantiated type U for which
|
||||
//U <: s (but 'null' itself, which is not a valid type)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t.inst != null)
|
||||
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
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>
|
||||
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>>)
|
||||
- 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>>))}
|
||||
1 error
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
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>
|
||||
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>>)
|
||||
1 error
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 7086586
|
||||
* @summary Inference producing null type argument
|
||||
* @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
class T7086586 {
|
||||
|
||||
<T> List<T> m(List<? super T> dummy) { return null; }
|
||||
|
||||
void test(List<?> l) {
|
||||
String s = m(l).get(0);
|
||||
Number n = m(l).get(0);
|
||||
Exception e = m(l).get(0);
|
||||
m(l).nonExistentMethod();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
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>)
|
||||
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>)
|
||||
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>)
|
||||
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>)
|
||||
4 errors
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 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 7086586
|
||||
*
|
||||
* @summary Inference producing null type argument
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
public class T7086586b {
|
||||
|
||||
int assertionCount = 0;
|
||||
|
||||
void assertTrue(boolean cond) {
|
||||
if (!cond) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
assertionCount++;
|
||||
}
|
||||
|
||||
<T> void m(List<? super T> dummy) { assertTrue(false); }
|
||||
<T> void m(Object dummy) { assertTrue(true); }
|
||||
|
||||
void test(List<?> l) {
|
||||
m(l);
|
||||
assertTrue(assertionCount == 1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new T7086586b().test(null);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user