Skip to content

Commit 188f378

Browse files
committed
Fix posttyper
1 parent b344155 commit 188f378

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,14 @@ extension (tree: Tree)
5959
tree.putAttachment(Captures, refs)
6060
refs
6161

62+
/** The type representing the capture set of retains annotation.
63+
*/
6264
def retainedSet(using Context): Type =
6365
tree match
6466
case Apply(TypeApply(_, refs :: Nil), _) => refs.tpe
6567
case _ =>
6668
if tree.symbol.maybeOwner == defn.RetainsCapAnnot
67-
then root.cap
68-
else NoType
69-
70-
/** The arguments of a @retains, @retainsCap or @retainsByName annotation */
71-
def retainedElems(using Context): List[Tree] = tree match
72-
case Apply(_, Typed(SeqLiteral(elems, _), _) :: Nil) =>
73-
elems
74-
case _ =>
75-
if tree.symbol.maybeOwner == defn.RetainsCapAnnot
76-
then ref(root.cap) :: Nil
77-
else Nil
69+
then root.cap else NoType
7870

7971
extension (tp: Type)
8072

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
311311
case ExprType(restp) =>
312312
def arrowText: Text = restp match
313313
case AnnotatedType(parent, ann) if ann.symbol == defn.RetainsByNameAnnot =>
314-
ann.tree.retainedElems match
315-
case ref :: Nil if ref.symbol == defn.captureRoot => Str("=>")
316-
case refs => Str("->") ~ toTextRetainedElems(refs)
314+
ann.tree.retainedSet.retainedElements match
315+
case ref :: Nil if ref.isCap => Str("=>")
316+
case refs => Str("->") ~ toTextRetainedElems(refs.map(r => ast.tpd.TypeTree(r)))
317317
case _ =>
318318
if Feature.pureFunsEnabled then "->" else "=>"
319319
changePrec(GlobalPrec)(arrowText ~ " " ~ toText(restp))

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
196196
val saved = inJavaAnnot
197197
inJavaAnnot = annot.symbol.is(JavaDefined)
198198
if (inJavaAnnot) checkValidJavaAnnotation(annot)
199-
try transform(annot)
199+
try
200+
val annotCtx = if annot.hasAttachment(untpd.RetainsAnnot)
201+
then ctx.addMode(Mode.InCaptureSet) else ctx
202+
transform(annot)(using annotCtx)
200203
finally inJavaAnnot = saved
201204
}
202205

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25322532
def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(using Context): Tree = {
25332533
val ref1 = typedExpr(tree.ref, SingletonTypeProto)
25342534
if ctx.mode.is(Mode.InCaptureSet) && ref1.symbol.is(Flags.CaptureParam) then
2535-
// println(s"typedSingletonTypeTree: $ref1 -> ${ref1.tpe.widen}")
25362535
return Ident(ref1.tpe.widen.asInstanceOf[TypeRef]).withSpan(tree.span)
25372536
checkStable(ref1.tpe, tree.srcPos, "singleton type")
25382537
assignType(cpy.SingletonTypeTree(tree)(ref1), ref1)

0 commit comments

Comments
 (0)