提交 339bcd3d 编写于 作者: M mcimadamore

7126754: Generics compilation failure casting List<? extends Set...> to List<Set...>

Summary: Problems with Types.rewriteQuantifiers not preserving variance
Reviewed-by: jjg
上级 92002391
/* /*
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -3600,39 +3600,44 @@ public class Types { ...@@ -3600,39 +3600,44 @@ public class Types {
@Override @Override
public Type visitCapturedType(CapturedType t, Void s) { public Type visitCapturedType(CapturedType t, Void s) {
Type bound = visitWildcardType(t.wildcard, null); Type w_bound = t.wildcard.type;
return (bound.contains(t)) ? Type bound = w_bound.contains(t) ?
erasure(bound) : erasure(w_bound) :
bound; visit(w_bound);
return rewriteAsWildcardType(visit(bound), t.wildcard.bound, t.wildcard.kind);
} }
@Override @Override
public Type visitTypeVar(TypeVar t, Void s) { public Type visitTypeVar(TypeVar t, Void s) {
if (rewriteTypeVars) { if (rewriteTypeVars) {
Type bound = high ? Type bound = t.bound.contains(t) ?
(t.bound.contains(t) ?
erasure(t.bound) : erasure(t.bound) :
visit(t.bound)) : visit(t.bound);
syms.botType; return rewriteAsWildcardType(bound, t, EXTENDS);
return rewriteAsWildcardType(bound, t); } else {
}
else
return t; return t;
}
} }
@Override @Override
public Type visitWildcardType(WildcardType t, Void s) { public Type visitWildcardType(WildcardType t, Void s) {
Type bound = high ? t.getExtendsBound() : Type bound2 = visit(t.type);
t.getSuperBound(); return t.type == bound2 ? t : rewriteAsWildcardType(bound2, t.bound, t.kind);
if (bound == null) }
bound = high ? syms.objectType : syms.botType;
return rewriteAsWildcardType(visit(bound), t.bound); private Type rewriteAsWildcardType(Type bound, TypeVar formal, BoundKind bk) {
} switch (bk) {
case EXTENDS: return high ?
private Type rewriteAsWildcardType(Type bound, TypeVar formal) { makeExtendsWildcard(B(bound), formal) :
return high ? makeExtendsWildcard(syms.objectType, formal);
makeExtendsWildcard(B(bound), formal) : case SUPER: return high ?
makeSuperWildcard(B(bound), formal); makeSuperWildcard(syms.botType, formal) :
makeSuperWildcard(B(bound), formal);
case UNBOUND: return makeExtendsWildcard(syms.objectType, formal);
default:
Assert.error("Invalid bound kind " + bk);
return null;
}
} }
Type B(Type t) { Type B(Type t) {
......
/*
* @test /nodynamiccopyright/
* @author mcimadamore
* @bug 7005671
* @summary Generics compilation failure casting List<? extends Set...> to List<Set...>
* @compile/fail/ref=T7126754.out -Xlint:unchecked -Werror -XDrawDiagnostics T7126754.java
*/
import java.util.List;
class T7126754 {
List<? extends List<? extends String>> c = null;
List<List<? extends String>> d = (List<List<? extends String>>)c;
}
T7126754.java:13:68: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.List<compiler.misc.type.captureof: 1, ? extends java.util.List<? extends java.lang.String>>, java.util.List<java.util.List<? extends java.lang.String>>
- 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.
先完成此消息的编辑!
想要评论请 注册