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