提交 4d5a4c58 编写于 作者: M mcimadamore

7041019: Bogus type-variable substitution with array types with dependencies on accessibility check

Summary: call to upperBound() when performing type-variable substitution on element type leads to unsoundness
Reviewed-by: jjg
上级 54b82be6
......@@ -2864,7 +2864,7 @@ public class Types {
if (elemtype == t.elemtype)
return t;
else
return new ArrayType(upperBound(elemtype), t.tsym);
return new ArrayType(elemtype, t.tsym);
}
@Override
......
......@@ -345,7 +345,7 @@ public class Resolve {
boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) {
return (t.hasTag(ARRAY))
? isAccessible(env, types.elemtype(t))
? isAccessible(env, types.upperBound(types.elemtype(t)))
: isAccessible(env, t.tsym, checkInner);
}
......
/*
* @test /nodynamiccopyright/
* @ignore 7041019 Bogus type-variable substitution with array types with dependencies on accessibility check
* @bug 7034511 7040883
* @bug 7034511 7040883 7041019
* @summary Loophole in typesafety
* @compile/fail/ref=T7034511a.out -XDrawDiagnostics T7034511a.java
*/
// backing out 7034511, see 7040883
class T7034511a {
interface A<T> {
......
T7034511a.java:18:14: compiler.err.cant.apply.symbol: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: java.lang.String[], compiler.misc.type.captureof: 1, ?[])
T7034511a.java:18:14: compiler.err.cant.apply.symbol: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String[], compiler.misc.type.captureof: 1, ?[]))
1 error
/*
* @test /nodynamiccopyright/
* @ignore 7041019 Bogus type-variable substitution with array types with dependencies on accessibility check
* @bug 7034511 7040883
* @bug 7034511 7040883 7041019
* @summary Loophole in typesafety
* @compile/fail/ref=T7034511b.out -XDrawDiagnostics T7034511b.java
*/
// backing out 7034511, see 7040883
class T7034511b {
static class MyList<E> {
E toArray(E[] e) { return null; }
......
T7034511b.java:14:11: compiler.err.cant.apply.symbol: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: java.lang.Object[], compiler.misc.type.captureof: 1, ?[])
T7034511b.java:14:11: compiler.err.cant.apply.symbol: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object[], compiler.misc.type.captureof: 1, ?[]))
1 error
/*
* 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 7034511 7040883 7041019
* @summary Bogus type-variable substitution with array types with dependencies on accessibility check
*
* @compile T7041019.java
*/
import java.util.List;
class T7041019 {
<E> List<E>[] m(List<E> l) { return null; }
void test(List<? extends String> ls) {
int i = m(ls).length;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册