# HG changeset patch # User vromero # Date 1444165156 25200 # Node ID eb290482d42f86d27a920ddce0393c6211b88acf # Parent fe2f2101a69278cfdf822b1a6f34d00115d7fcd7 8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables Reviewed-by: mcimadamore diff -r fe2f2101a692 -r eb290482d42f langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Tue Oct 06 08:43:24 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java Tue Oct 06 13:59:16 2015 -0700 @@ -3781,11 +3781,24 @@ * 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 Integer visitErrorType(ErrorType t, Void ignored) { return 0; } - }; + } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable"> diff -r fe2f2101a692 -r eb290482d42f langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Tue Oct 06 08:43:24 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java Tue Oct 06 13:59:16 2015 -0700 @@ -1254,9 +1254,9 @@ 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; }