Skip to content

Ensure all capture variables carry the attachment #23162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3053,18 +3053,25 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if sym.isOpaqueAlias then
checkFullyAppliedType(rhs1, "Opaque type alias must be fully applied, but ")
checkNoContextFunctionType(rhs1)
var attachCap = false
if Feature.ccEnabled then
val isCap = tdef.hasAttachment(CaptureVar)
rhs1 match
case TypeBoundsTree(lo, hi, _) =>
if !isCap && (lo.tpe.derivesFrom(defn.Caps_CapSet) ^ hi.tpe.derivesFrom(defn.Caps_CapSet)) then
val loIsCap = lo.tpe.derivesFrom(defn.Caps_CapSet)
val hiIsCap = hi.tpe.derivesFrom(defn.Caps_CapSet)
if !isCap && (loIsCap ^ hiIsCap) then
report.error(em"Illegal type bounds: >: $lo <: $hi. Capture-set bounds cannot be mixed with type bounds of other kinds", rhs.srcPos)
if isCap && !(lo.tpe.derivesFrom(defn.Caps_CapSet) && hi.tpe.derivesFrom(defn.Caps_CapSet)) then
if isCap && !(loIsCap && hiIsCap) then
report.error(em"Illegal type bounds: >: $lo <: $hi. $name^ can only have capture sets as bounds", rhs.srcPos)
attachCap = !isCap && loIsCap && hiIsCap
case LambdaTypeTree(_, _) if isCap =>
report.error(em"`$name` cannot have type parameters, because it ranges over capture sets", rhs.srcPos)
case _ =>
assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
val res = assignType(cpy.TypeDef(tdef)(name, rhs1), sym)
if Feature.ccEnabled && attachCap then
res.putAttachment(CaptureVar, ())
res
}

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