Skip to content

Commit d3f4770

Browse files
committed
-Xcheck-macros: add hint when a symbol in created twice
Closes #16363
1 parent 13b8d7d commit d3f4770

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,12 +2973,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
29732973
t match
29742974
case t: tpd.DefTree =>
29752975
val defOwner = t.symbol.owner
2976-
assert(defOwner == owner,
2976+
assert(defOwner == owner, {
2977+
val ownerName = owner.fullName
2978+
val defOwnerName = defOwner.fullName
2979+
val duplicateSymbolHint =
2980+
if ownerName == defOwnerName then "These are two different symbols instances with the same name. The symbol should have been instantiated only once.\n"
2981+
else ""
29772982
s"""Tree had an unexpected owner for ${t.symbol}
29782983
|Expected: $owner (${owner.fullName})
29792984
|But was: $defOwner (${defOwner.fullName})
2980-
|
2981-
|
2985+
|$duplicateSymbolHint
29822986
|The code of the definition of ${t.symbol} is
29832987
|${Printer.TreeCode.show(t)}
29842988
|
@@ -2992,7 +2996,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
29922996
|
29932997
|Tip: The owner of a tree can be changed using method `Tree.changeOwner`.
29942998
|Tip: The default owner of definitions created in quotes can be changed using method `Symbol.asQuotes`.
2995-
|""".stripMargin)
2999+
|""".stripMargin
3000+
})
29963001
case _ => traverseChildren(t)
29973002
}.traverse(tree)
29983003

0 commit comments

Comments
 (0)