From 0fd8804b3a2ce9a2099a3d7c1b756fec637f9d1c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 26 Oct 2016 16:26:21 +0200 Subject: Make cloned trees have new uniqueIds They used to share the same id as the tree they were cloned from, which makes id's not really unique. --- src/dotty/tools/dotc/ast/Trees.scala | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index 4c63a67ce..9108a4d22 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -60,15 +60,19 @@ object Trees { with Cloneable { if (Stats.enabled) ntrees += 1 + + private def nxId = { + nextId += 1 + //assert(nextId != 199, this) + nextId + } /** A unique identifier for this tree. Used for debugging, and potentially * tracking presentation compiler interactions */ - val uniqueId = { - nextId += 1 - //assert(nextId != 214, this) - nextId - } + private var myUniqueId: Int = nxId + + def uniqueId = myUniqueId /** The type constructor at the root of the tree */ type ThisTree[T >: Untyped] <: Tree[T] @@ -188,6 +192,12 @@ object Trees { override def hashCode(): Int = uniqueId // for debugging; was: System.identityHashCode(this) override def equals(that: Any) = this eq that.asInstanceOf[AnyRef] + + override def clone: Tree[T] = { + val tree = super.clone.asInstanceOf[Tree[T]] + tree.myUniqueId = nxId + tree + } } class UnAssignedTypeException[T >: Untyped](tree: Tree[T]) extends RuntimeException { -- cgit v1.2.3