提交 e7866354 编写于 作者: M mcimadamore

6838943: inference: javac is not handling type-variable substitution properly

Summary: free type-variables are being replaced with type-variables bound to forall type leading to unsoundness
Reviewed-by: jjg, dlsmith
上级 b841fb52
......@@ -2259,6 +2259,13 @@ public class Types {
@Override
public Type visitForAll(ForAll t, Void ignored) {
if (Type.containsAny(to, t.tvars)) {
//perform alpha-renaming of free-variables in 't'
//if 'to' types contain variables that are free in 't'
List<Type> freevars = newInstances(t.tvars);
t = new ForAll(freevars,
Types.this.subst(t.qtype, t.tvars, freevars));
}
List<Type> tvars1 = substBounds(t.tvars, from, to);
Type qtype1 = subst(t.qtype);
if (tvars1 == t.tvars && qtype1 == t.qtype) {
......
/**
* @test /nodynamiccopyright/
* @bug 6838943
* @summary inference: javac is not handling type-variable substitution properly
* @compile/fail/ref=T6838943.out -XDrawDiagnostics T6838943.java
*/
class T6838943 {
static class A<X> {}
static class B {}
static class C<X> {
<Z> void m(X x, Z z) {
C<A<Z>> c = new C<A<Z>>();
c.m(new A<B>(), new B()); //should fail
}
}
}
T6838943.java:13:14: compiler.err.cant.apply.symbol.1: kindname.method, m, T6838943.A<Z>,Z, T6838943.A<T6838943.B>,T6838943.B, kindname.class, T6838943.C<X>, (compiler.misc.infer.no.conforming.assignment.exists: Z, T6838943.A<T6838943.B>, T6838943.A<Z>)
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册