@@ -103,17 +103,17 @@ object MainProxies {
103
103
val body = Try (call, handler :: Nil , EmptyTree )
104
104
val mainArg = ValDef (nme.args, TypeTree (defn.ArrayType .appliedTo(defn.StringType )), EmptyTree )
105
105
.withFlags(Param )
106
- /** Replace typed `Ident`s that have been typed with a TypeSplice with the reference to the symbol.
107
- * The annotations will be retype-checked in another scope that may not have the same imports.
106
+
107
+ /** This context is used to create the `TypeSplices` wrapping annotations
108
+ * below. These should have `mainFun` as their owner (and not the
109
+ * enclosing package class that we would get otherwise) so that
110
+ * subsequent owner changes (for example in `Typer.typedTypedSplice`) are
111
+ * correct. See #22364 and associated tests.
108
112
*/
109
- def insertTypeSplices = new TreeMap {
110
- override def transform (tree : Tree )(using Context ): Tree = tree match
111
- case tree : tpd.Ident @ unchecked => TypedSplice (tree)
112
- case tree => super .transform(tree)
113
- }
113
+ val annotsCtx = ctx.fresh.setOwner(mainFun)
114
114
val annots = mainFun.annotations
115
115
.filterNot(_.matches(defn.MainAnnot ))
116
- .map(annot => insertTypeSplices.transform (annot.tree))
116
+ .map(annot => TypedSplice (annot.tree)( using annotsCtx ))
117
117
val mainMeth = DefDef (nme.main, (mainArg :: Nil ) :: Nil , TypeTree (defn.UnitType ), body)
118
118
.withFlags(JavaStatic | Synthetic )
119
119
.withAnnotations(annots)
0 commit comments