Skip to content

Commit e57fc00

Browse files
committed
Add CaptureVar attachment to TypeDef and its rhs
We cannot post-process the typedef in typedTypeDef in the typer, because adaptation of the rhs prematurely sets the symbol info to the old bounds pre-expansion, which will be caught by checkBounds in posttyper. It is easier to mark the rhs as well and do the expansion in typedTypeBoundsTree.
1 parent 630a20f commit e57fc00

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,6 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
533533
def makeCapsOf(tp: RefTree)(using Context): Tree =
534534
TypeApply(capsInternalDot(nme.capsOf), tp :: Nil)
535535

536-
// Capture set variable `[C^]` becomes: `[C >: CapSet <: CapSet^{cap}]`
537-
def makeCapsBound(refsL: List[Tree] = Nil, refsU: List[Tree] = Nil)(using Context): TypeBoundsTree =
538-
val lower = refsL match
539-
case Nil => Select(scalaDot(nme.caps), tpnme.CapSet)
540-
case refsL => makeRetaining(Select(scalaDot(nme.caps), tpnme.CapSet), refsL, tpnme.retains)
541-
val upper =
542-
makeRetaining(Select(scalaDot(nme.caps), tpnme.CapSet), refsU, if refsU.isEmpty then tpnme.retainsCap else tpnme.retains)
543-
TypeBoundsTree(lower, upper)
544-
545536
def makeConstructor(tparams: List[TypeDef], vparamss: List[List[ValDef]], rhs: Tree = EmptyTree)(using Context): DefDef =
546537
DefDef(nme.CONSTRUCTOR, joinParams(tparams, vparamss), TypeTree(), rhs)
547538

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,12 +3560,15 @@ object Parsers {
35603560
if !isCap && paramOwner.acceptsCtxBounds then typeAndCtxBounds(name)
35613561
else if !isCap && sourceVersion.enablesNewGivens && paramOwner == ParamOwner.Type then typeAndCtxBounds(name)
35623562
else typeBounds()
3563+
val res = TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods)
35633564
if isCap then
3565+
res.pushAttachment(CaptureVar, ())
3566+
// putting the attachment here as well makes post-processing in the typer easier
35643567
bounds.pushAttachment(CaptureVar, ())
35653568
val t = contextBounds(name)
35663569
if t.nonEmpty then
35673570
syntaxError(em"capture parameters cannot have context bounds", t.head.span)
3568-
TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3571+
res
35693572
}
35703573
}
35713574
commaSeparated(() => typeParam())
@@ -4114,7 +4117,9 @@ object Parsers {
41144117
tdef.pushAttachment(Backquoted, ())
41154118
if isCapDef then rhs.match
41164119
case ContextBounds(_, _) => syntaxError(em"capture-set member declarations cannot have context bounds", rhs.span)
4117-
case rhs => rhs.pushAttachment(CaptureVar, ())
4120+
case rhs => tdef.pushAttachment(CaptureVar, ())
4121+
// putting the attachment here as well makes post-processing in the typer easier
4122+
rhs.pushAttachment(CaptureVar, ())
41184123
finalizeDef(tdef, mods, start)
41194124
}
41204125

0 commit comments

Comments
 (0)