From 7e52fb910b8547930f203233e46140a2daf8b511 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 9 Mar 2013 13:03:22 +0100 Subject: SI-7226 Fix inference regression caused by TypeVar equality. TypeVars, being mutable creatures, mustn't have structural equality/hashing, otherwise TypeRefs that differ only by having distinct TypeVars as components get wrongly uniqued together. The reported bug showed the disaterous consequences: constraints from the `C?[Int]` in the return type applied to the `?C[?A]` in the parameter list. This commit overrides `equals` and `hashCode` in `TypeVar` to use reference equality. An alternative fix would be to drop the `case`-ness of the class, as was the case before 0cde930b when this regressed. --- src/reflect/scala/reflect/internal/Types.scala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index ea193465ad..a27b37dae5 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -3052,6 +3052,12 @@ trait Types extends api.Types { self: SymbolTable => val origin: Type, var constr: TypeConstraint ) extends Type { + + // We don't want case class equality/hashing as TypeVar-s are mutable, + // and TypeRefs based on them get wrongly `uniqued` otherwise. See SI-7226. + override def hashCode(): Int = System.identityHashCode(this) + override def equals(other: Any): Boolean = this eq other.asInstanceOf[AnyRef] + def untouchable = false // by other typevars override def params: List[Symbol] = Nil override def typeArgs: List[Type] = Nil -- cgit v1.2.3