Skip to content

Make sure we don't recheck closure bodies twice #23066

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 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,12 @@ class CheckCaptures extends Recheck, SymTransformer:
// TODO follow up on this
try
matchParams(mdef.paramss, pt)
recheckDef(mdef, mdef.symbol)
capt.println(i"recheck closure block $mdef: ${mdef.symbol.infoOrCompleter}")
if !mdef.symbol.isCompleted then
mdef.symbol.ensureCompleted() // this will recheck def
else
recheckDef(mdef, mdef.symbol)

recheckClosure(expr, pt, forceDependent = true)
finally
openClosures = openClosures.tail
Expand Down Expand Up @@ -1112,6 +1117,10 @@ class CheckCaptures extends Recheck, SymTransformer:
finally
curEnv = saved

override def recheckTypeDef(tree: TypeDef, sym: Symbol)(using Context): Type =
try super.recheckTypeDef(tree, sym)
finally completed += sym

/** Recheck classDef by enforcing the following class-specific capture set relations:
* 1. The capture set of a class includes the capture sets of its parents.
* 2. The capture set of the self type of a class includes the capture set of the class.
Expand Down Expand Up @@ -1156,6 +1165,7 @@ class CheckCaptures extends Recheck, SymTransformer:
ccState.inNestedLevelUnless(cls.is(Module)):
super.recheckClassDef(tree, impl, cls)
finally
completed += cls
curEnv = saved

/** If type is of the form `T @requiresCapability(x)`,
Expand Down
14 changes: 8 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,14 @@ abstract class Recheck extends Phase, SymTransformer:
if !skipRecheck(sym) then recheckDef(tree, sym)
sym.termRef
case tree: TypeDef =>
// TODO: Should we allow for completers as for ValDefs or DefDefs?
tree.rhs match
case impl: Template =>
recheckClassDef(tree, impl, sym.asClass)(using ctx.localContext(tree, sym))
case _ =>
recheckTypeDef(tree, sym)(using ctx.localContext(tree, sym))
if !skipRecheck(sym) then
// TODO: Should we allow for completers as for ValDefs or DefDefs?
tree.rhs match
case impl: Template =>
recheckClassDef(tree, impl, sym.asClass)(using ctx.localContext(tree, sym))
case _ =>
recheckTypeDef(tree, sym)(using ctx.localContext(tree, sym))
sym.typeRef
case tree: Labeled => recheckLabeled(tree, pt)

def recheckUnnamed(tree: Tree, pt: Type): Type = tree match
Expand Down
Loading