8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2015-10-06 13:59:16 -07:00
parent a113b52db0
commit 38c2534531
2 changed files with 18 additions and 5 deletions

View File

@ -3781,11 +3781,24 @@ public class Types {
* Compute a hash code on a type.
*/
public int hashCode(Type t) {
return hashCode.visit(t);
return hashCode(t, false);
}
public int hashCode(Type t, boolean strict) {
return strict ?
hashCodeStrictVisitor.visit(t) :
hashCodeVisitor.visit(t);
}
// where
private static final UnaryVisitor<Integer> hashCode = new UnaryVisitor<Integer>() {
private static final HashCodeVisitor hashCodeVisitor = new HashCodeVisitor();
private static final HashCodeVisitor hashCodeStrictVisitor = new HashCodeVisitor() {
@Override
public Integer visitTypeVar(TypeVar t, Void ignored) {
return System.identityHashCode(t);
}
};
private static class HashCodeVisitor extends UnaryVisitor<Integer> {
public Integer visitType(Type t, Void ignored) {
return t.getTag().ordinal();
}
@ -3841,7 +3854,7 @@ public class Types {
public Integer visitErrorType(ErrorType t, Void ignored) {
return 0;
}
};
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable">

View File

@ -1254,9 +1254,9 @@ public class Infer {
public int hashCode() {
int result = opKind.hashCode();
result *= 127;
result += types.hashCode(op1);
result += types.hashCode(op1, true);
result *= 127;
result += types.hashCode(op2);
result += types.hashCode(op2, true);
return result;
}