@@ -14,6 +14,7 @@ import dotty.tools.dotc.inlines.Inlines
14
14
import dotty .tools .dotc .ast .TreeMapWithImplicits
15
15
import dotty .tools .dotc .core .DenotTransformers .IdentityDenotTransformer
16
16
17
+ import scala .collection .mutable .ListBuffer
17
18
18
19
/** Inlines all calls to inline methods that are not in an inline method or a quote */
19
20
class Inlining extends MacroTransform {
@@ -66,7 +67,7 @@ class Inlining extends MacroTransform {
66
67
/** List of top level classes added by macro annotation in a package object.
67
68
* These are added to the PackageDef that owns this particular package object.
68
69
*/
69
- private val topClasses = new collection.mutable. ListBuffer [Tree ]
70
+ private val newTopClasses = MutableSymbolMap [ ListBuffer [Tree ]]()
70
71
71
72
override def transform (tree : Tree )(using Context ): Tree = {
72
73
tree match
@@ -82,10 +83,11 @@ class Inlining extends MacroTransform {
82
83
val trees1 = trees.map(super .transform)
83
84
84
85
// Find classes added to the top level from a package object
85
- val (topClasses0 , trees2) =
86
+ val (topClasses , trees2) =
86
87
if ctx.owner.isPackageObject then trees1.partition(_.symbol.owner == ctx.owner.owner)
87
88
else (Nil , trees1)
88
- topClasses ++= topClasses0
89
+ if topClasses.nonEmpty then
90
+ newTopClasses.getOrElseUpdate(ctx.owner.owner, new ListBuffer ) ++= topClasses
89
91
90
92
flatTree(trees2)
91
93
else super .transform(tree)
@@ -101,10 +103,13 @@ class Inlining extends MacroTransform {
101
103
super .transform(tree)(using StagingContext .spliceContext)
102
104
case _ : PackageDef =>
103
105
super .transform(tree) match
104
- case tree1 : PackageDef if ! topClasses.isEmpty =>
105
- val newStats = tree1.stats ::: topClasses.result()
106
- topClasses.clear()
107
- cpy.PackageDef (tree1)(tree1.pid, newStats)
106
+ case tree1 : PackageDef =>
107
+ newTopClasses.get(tree.symbol.moduleClass) match
108
+ case Some (topClasses) =>
109
+ newTopClasses.remove(tree.symbol.moduleClass)
110
+ val newStats = tree1.stats ::: topClasses.result()
111
+ cpy.PackageDef (tree1)(tree1.pid, newStats)
112
+ case _ => tree1
108
113
case tree1 => tree1
109
114
case _ =>
110
115
super .transform(tree)
0 commit comments