changeset 3045:7ef2c66892a3 jdk9-b85

8138914: javac, method visitTypeVar() at visitor Types.hashCode generates the same hash code for different type variables Reviewed-by: mcimadamore
author vromero
date Tue, 06 Oct 2015 13:59:16 -0700
parents 6d1efeaa04f2
children e481951ea027 21b0862fdd32
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
diffstat 2 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Oct 06 08:43:24 2015 -0700
+++ b/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">
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Oct 06 08:43:24 2015 -0700
+++ b/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;
         }