From 38c25345319d6636fffd2a4e2f37e59804834e70 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Tue, 6 Oct 2015 13:59:16 -0700 Subject: [PATCH] 8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables Reviewed-by: mcimadamore --- .../com/sun/tools/javac/code/Types.java | 19 ++++++++++++++++--- .../com/sun/tools/javac/comp/Infer.java | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java index 781f2c2048c..1c7e35f3561 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java @@ -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 hashCode = new UnaryVisitor() { + 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 { 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; } - }; + } // // diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java index f92c1c5efa5..fa61200d21e 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java @@ -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; }