Skip to content

Commit 5a9b616

Browse files
authored
-Xcheck-macros: add hint when a symbol in created twice (#16733)
Closes #16363
2 parents 8360a31 + d3f4770 commit 5a9b616

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
@@ -3028,12 +3028,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
30283028
t match
30293029
case t: tpd.DefTree =>
30303030
val defOwner = t.symbol.owner
3031-
assert(defOwner == owner,
3031+
assert(defOwner == owner, {
3032+
val ownerName = owner.fullName
3033+
val defOwnerName = defOwner.fullName
3034+
val duplicateSymbolHint =
3035+
if ownerName == defOwnerName then "These are two different symbols instances with the same name. The symbol should have been instantiated only once.\n"
3036+
else ""
30323037
s"""Tree had an unexpected owner for ${t.symbol}
30333038
|Expected: $owner (${owner.fullName})
30343039
|But was: $defOwner (${defOwner.fullName})
3035-
|
3036-
|
3040+
|$duplicateSymbolHint
30373041
|The code of the definition of ${t.symbol} is
30383042
|${Printer.TreeCode.show(t)}
30393043
|
@@ -3047,7 +3051,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
30473051
|
30483052
|Tip: The owner of a tree can be changed using method `Tree.changeOwner`.
30493053
|Tip: The default owner of definitions created in quotes can be changed using method `Symbol.asQuotes`.
3050-
|""".stripMargin)
3054+
|""".stripMargin
3055+
})
30513056
case _ => traverseChildren(t)
30523057
}.traverse(tree)
30533058

0 commit comments

Comments
 (0)