Skip to content

Commit 64f8aa2

Browse files
committed
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.
1 parent 3e84316 commit 64f8aa2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ object Trees {
6060
with Cloneable {
6161

6262
if (Stats.enabled) ntrees += 1
63+
64+
private def nxId = {
65+
nextId += 1
66+
//assert(nextId != 199, this)
67+
nextId
68+
}
6369

6470
/** A unique identifier for this tree. Used for debugging, and potentially
6571
* tracking presentation compiler interactions
6672
*/
67-
val uniqueId = {
68-
nextId += 1
69-
//assert(nextId != 214, this)
70-
nextId
71-
}
73+
private var myUniqueId: Int = nxId
74+
75+
def uniqueId = myUniqueId
7276

7377
/** The type constructor at the root of the tree */
7478
type ThisTree[T >: Untyped] <: Tree[T]
@@ -188,6 +192,12 @@ object Trees {
188192

189193
override def hashCode(): Int = uniqueId // for debugging; was: System.identityHashCode(this)
190194
override def equals(that: Any) = this eq that.asInstanceOf[AnyRef]
195+
196+
override def clone: Tree[T] = {
197+
val tree = super.clone.asInstanceOf[Tree[T]]
198+
tree.myUniqueId = nxId
199+
tree
200+
}
191201
}
192202

193203
class UnAssignedTypeException[T >: Untyped](tree: Tree[T]) extends RuntimeException {

0 commit comments

Comments
 (0)