From d3f4770c2e9157e96fa8a0f755457615681d1cd1 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 20 Jan 2023 15:38:13 +0100 Subject: [PATCH] -Xcheck-macros: add hint when a symbol in created twice Closes #16363 --- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index dd6471a882bd..7f90b018bea0 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2973,12 +2973,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler t match case t: tpd.DefTree => val defOwner = t.symbol.owner - assert(defOwner == owner, + assert(defOwner == owner, { + val ownerName = owner.fullName + val defOwnerName = defOwner.fullName + val duplicateSymbolHint = + if ownerName == defOwnerName then "These are two different symbols instances with the same name. The symbol should have been instantiated only once.\n" + else "" s"""Tree had an unexpected owner for ${t.symbol} |Expected: $owner (${owner.fullName}) |But was: $defOwner (${defOwner.fullName}) - | - | + |$duplicateSymbolHint |The code of the definition of ${t.symbol} is |${Printer.TreeCode.show(t)} | @@ -2992,7 +2996,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |Tip: The owner of a tree can be changed using method `Tree.changeOwner`. |Tip: The default owner of definitions created in quotes can be changed using method `Symbol.asQuotes`. - |""".stripMargin) + |""".stripMargin + }) case _ => traverseChildren(t) }.traverse(tree)