Skip to content

Commit f842979

Browse files
committed
Don't transform AnnotatedTypes to CapturingTypes
1 parent 7f63049 commit f842979

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

compiler/src/dotty/tools/dotc/core/CaptureSet.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import printing.{Showable, Printer}
1212
import printing.Texts.*
1313
import util.SimpleIdentitySet
1414
import util.common.alwaysTrue
15-
import cc.CapturingType
15+
import cc.*
1616

1717
/** A class for capture sets. Capture sets can be constants or variables.
1818
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -158,6 +158,9 @@ sealed abstract class CaptureSet extends Showable:
158158
((NoType: Type) /: elems) ((tp, ref) =>
159159
if tp.exists then OrType(tp, ref, soft = false) else ref)
160160

161+
def toRegularAnnotation(using Context): Annotation =
162+
Annotation(CaptureAnnotation(this).tree)
163+
161164
override def toText(printer: Printer): Text =
162165
Str("{") ~ Text(elems.toList.map(printer.toTextCaptureRef), ", ") ~ Str("}")
163166

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import scala.util.hashing.{ MurmurHash3 => hashing }
3838
import config.Printers.{core, typr, matchTypes}
3939
import reporting.{trace, Message}
4040
import java.lang.ref.WeakReference
41-
import cc.{CapturingType, derivedCapturingType}
41+
import cc.{CapturingType, derivedCapturingType, retainedElems}
4242
import CaptureSet.CompareResult
4343

4444
import scala.annotation.internal.sharable
@@ -3773,7 +3773,21 @@ object Types {
37733773
CapturingType(parent1, CaptureSet(elems1)),
37743774
CapturingType(parent1, CaptureSet.universal))
37753775
case AnnotatedType(parent, ann) if ann.refersToParamOf(thisLambdaType) =>
3776-
mapOver(parent)
3776+
val parent1 = mapOver(parent)
3777+
if ann.symbol == defn.RetainsAnnot then
3778+
val elems = retainedElems(ann.tree) // ^^^ needed? or maybe just use {} as lower bound?
3779+
val elems1 = elems.filter { elem =>
3780+
elem.tpe match
3781+
case tp @ TermParamRef(`thisLambdaType`, _) => false
3782+
case _ => true
3783+
}
3784+
assert(elems1.size != elems.size)
3785+
val lower = Annotation(defn.RetainsAnnot, repeated(elems1, TypeTree(defn.AnyType)))
3786+
range(
3787+
AnnotatedType(parent1, lower),
3788+
AnnotatedType(parent1, CaptureSet.universal.toRegularAnnotation))
3789+
else
3790+
parent1
37773791
case _ => mapOver(tp)
37783792
}
37793793
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class CheckCaptures extends Recheck:
146146
addVars(cleanType(tp))
147147
end reinfer
148148

149-
if inferred then reinfer(tp) else mapType(tp)
149+
if inferred then reinfer(tp) else tp//mapType(tp)
150150
end transformType
151151

152152
private var curEnv: Env = Env(NoSymbol, CaptureSet.empty, false, null)

0 commit comments

Comments
 (0)