@@ -386,6 +386,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
386386 /** Property key for contextual Apply trees of the form `fn given arg` */
387387 val KindOfApply : Property .StickyKey [ApplyKind ] = Property .StickyKey ()
388388
389+ val RetainsAnnot : Property .StickyKey [Unit ] = Property .StickyKey ()
390+
389391 // ------ Creation methods for untyped only -----------------
390392
391393 def Ident (name : Name )(implicit src : SourceFile ): Ident = new Ident (name)
@@ -528,7 +530,16 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
528530 Select (scalaDot(nme.caps), nme.CAPTURE_ROOT )
529531
530532 def makeRetaining (parent : Tree , refs : List [Tree ], annotName : TypeName )(using Context ): Annotated =
531- Annotated (parent, New (scalaAnnotationDot(annotName), List (refs)))
533+ var annot : Tree = scalaAnnotationDot(annotName)
534+ if annotName == tpnme.retainsCap then
535+ annot = New (annot, Nil )
536+ else
537+ val trefs =
538+ if refs.isEmpty then ref(defn.NothingType )
539+ else refs.map(SingletonTypeTree ).reduce[Tree ]((a, b) => makeOrType(a, b))
540+ annot = New (AppliedTypeTree (annot, trefs :: Nil ), Nil )
541+ annot.putAttachment(RetainsAnnot , ())
542+ Annotated (parent, annot)
532543
533544 def makeCapsOf (tp : RefTree )(using Context ): Tree =
534545 TypeApply (capsInternalDot(nme.capsOf), tp :: Nil )
@@ -563,6 +574,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
563574 def makeAndType (left : Tree , right : Tree )(using Context ): AppliedTypeTree =
564575 AppliedTypeTree (ref(defn.andType.typeRef), left :: right :: Nil )
565576
577+ def makeOrType (left : Tree , right : Tree )(using Context ): AppliedTypeTree =
578+ AppliedTypeTree (ref(defn.orType.typeRef), left :: right :: Nil )
579+
566580 def makeParameter (pname : TermName , tpe : Tree , mods : Modifiers , isBackquoted : Boolean = false )(using Context ): ValDef = {
567581 val vdef = ValDef (pname, tpe, EmptyTree )
568582 if (isBackquoted) vdef.pushAttachment(Backquoted , ())
0 commit comments