提交 8271534a 编写于 作者: M mcimadamore

7123100: javac fails with java.lang.StackOverflowError

Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg
上级 339bcd3d
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2012, 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
......@@ -332,25 +332,29 @@ public class Infer {
//replace uninferred type-vars
targs = types.subst(targs,
that.tvars,
instaniateAsUninferredVars(undetvars, that.tvars));
instantiateAsUninferredVars(undetvars, that.tvars));
}
return chk.checkType(warn.pos(), that.inst(targs, types), to);
}
//where
private List<Type> instaniateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
Assert.check(undetvars.length() == tvars.length());
ListBuffer<Type> new_targs = ListBuffer.lb();
//step 1 - create syntethic captured vars
//step 1 - create synthetic captured vars
for (Type t : undetvars) {
UndetVar uv = (UndetVar)t;
Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
new_targs = new_targs.append(newArg);
}
//step 2 - replace synthetic vars in their bounds
List<Type> formals = tvars;
for (Type t : new_targs.toList()) {
CapturedType ct = (CapturedType)t;
ct.bound = types.subst(ct.bound, tvars, new_targs.toList());
WildcardType wt = new WildcardType(ct.bound, BoundKind.EXTENDS, syms.boundClass);
WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass);
wt.bound = (TypeVar)formals.head;
ct.wildcard = wt;
formals = formals.tail;
}
return new_targs.toList();
}
......
/*
* @test /nodynamiccopyright/
* @bug 7123100
* @summary javac fails with java.lang.StackOverflowError
* @compile/fail/ref=T7123100a.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100a.java
*/
class T7123100a {
<E extends Enum<E>> E m() {
return null;
}
<Z> void test() {
Z z = (Z)m();
}
}
T7123100a.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z
- compiler.err.warnings.and.werror
1 error
1 warning
/*
* @test /nodynamiccopyright/
* @bug 7123100
* @summary javac fails with java.lang.StackOverflowError
* @compile/fail/ref=T7123100b.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100b.java
*/
class T7123100b {
<Z> void test(Enum<?> e) {
Z z = (Z)e;
}
}
T7123100b.java:10:18: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
- compiler.err.warnings.and.werror
1 error
1 warning
/*
* @test /nodynamiccopyright/
* @bug 7123100
* @summary javac fails with java.lang.StackOverflowError
* @compile/fail/ref=T7123100c.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100c.java
*/
class T7123100c {
<E> E m(E e) {
return null;
}
<Z> void test(Enum<?> e) {
Z z = (Z)m(e);
}
}
T7123100c.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
- compiler.err.warnings.and.werror
1 error
1 warning
/*
* @test /nodynamiccopyright/
* @bug 7123100
* @summary javac fails with java.lang.StackOverflowError
* @compile/fail/ref=T7123100d.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100d.java
*/
class T7123100d {
<E extends Enum<E>> E m(Enum<E> e) {
return null;
}
<Z> void test(Enum<?> e) {
Z z = (Z)m(e);
}
}
T7123100d.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z
- compiler.err.warnings.and.werror
1 error
1 warning
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册