Skip to content

Commit a553986

Browse files
authored
Ensure all capture variables carry the attachment (#23162)
Declarations like `type C <: {cap}` were missing the `CaptureVar` attachment after post-processing in typer. This PR ensures that the attachment is added.
2 parents da9cc38 + fb4c8e1 commit a553986

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,18 +3053,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
30533053
if sym.isOpaqueAlias then
30543054
checkFullyAppliedType(rhs1, "Opaque type alias must be fully applied, but ")
30553055
checkNoContextFunctionType(rhs1)
3056+
var attachCap = false
30563057
if Feature.ccEnabled then
30573058
val isCap = tdef.hasAttachment(CaptureVar)
30583059
rhs1 match
30593060
case TypeBoundsTree(lo, hi, _) =>
3060-
if !isCap && (lo.tpe.derivesFrom(defn.Caps_CapSet) ^ hi.tpe.derivesFrom(defn.Caps_CapSet)) then
3061+
val loIsCap = lo.tpe.derivesFrom(defn.Caps_CapSet)
3062+
val hiIsCap = hi.tpe.derivesFrom(defn.Caps_CapSet)
3063+
if !isCap && (loIsCap ^ hiIsCap) then
30613064
report.error(em"Illegal type bounds: >: $lo <: $hi. Capture-set bounds cannot be mixed with type bounds of other kinds", rhs.srcPos)
3062-
if isCap && !(lo.tpe.derivesFrom(defn.Caps_CapSet) && hi.tpe.derivesFrom(defn.Caps_CapSet)) then
3065+
if isCap && !(loIsCap && hiIsCap) then
30633066
report.error(em"Illegal type bounds: >: $lo <: $hi. $name^ can only have capture sets as bounds", rhs.srcPos)
3067+
attachCap = !isCap && loIsCap && hiIsCap
30643068
case LambdaTypeTree(_, _) if isCap =>
30653069
report.error(em"`$name` cannot have type parameters, because it ranges over capture sets", rhs.srcPos)
30663070
case _ =>
3067-
assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
3071+
val res = assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
3072+
if Feature.ccEnabled && attachCap then
3073+
res.putAttachment(CaptureVar, ())
3074+
res
30683075
}
30693076

30703077
def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(using Context): Tree = ctx.profiler.onTypedDef(cls) {

0 commit comments

Comments
 (0)