Skip to content

Commit

Permalink
-Xcheck-macros: add hint when a symbol in created twice (#16733)
Browse files Browse the repository at this point in the history
Closes #16363
  • Loading branch information
smarter authored May 9, 2023
2 parents 8360a31 + d3f4770 commit 5a9b616
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3028,12 +3028,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)}
|
Expand All @@ -3047,7 +3051,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)

Expand Down

0 comments on commit 5a9b616

Please sign in to comment.