Skip to content

Commit a25677e

Browse files
committed
use pattern matching and closureDef extractor
1 parent 8bab429 commit a25677e

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -507,19 +507,6 @@ class CheckCaptures extends Recheck, SymTransformer:
507507
recheckFinish(result, arg, pt)
508508
*/
509509

510-
extension (tree: Tree)
511-
private def isFunctionLiteral(using Context): Boolean = tree match
512-
case Block((defTree @ DefDef(_, _, _, _)) :: Nil, Closure(_, meth, _)) =>
513-
val defSym = defTree.symbol
514-
val methSym = meth.symbol
515-
defSym.eq(methSym)
516-
case _ =>
517-
false
518-
519-
private def isRefTree: Boolean = tree match
520-
case _: RefTree => true
521-
case _ => false
522-
523510
/** If expected type `pt` is boxed and the tree is a function or a reference,
524511
* don't propagate free variables.
525512
* Otherwise, if the result type is boxed, simulate an unboxing by
@@ -528,8 +515,12 @@ class CheckCaptures extends Recheck, SymTransformer:
528515
override def recheck(tree: Tree, pt: Type = WildcardType)(using Context): Type =
529516
if tree.isTerm && pt.isBoxedCapturing then
530517
val saved = curEnv
531-
if tree.isRefTree || tree.isFunctionLiteral then
532-
curEnv = Env(curEnv.owner, nestedInOwner = false, CaptureSet.Var(), isBoxed = true, curEnv)
518+
519+
tree match
520+
case _: RefTree | closureDef(_) =>
521+
curEnv = Env(curEnv.owner, nestedInOwner = false, CaptureSet.Var(), isBoxed = true, curEnv)
522+
case _ =>
523+
533524
try super.recheck(tree, pt)
534525
finally curEnv = saved
535526
else

0 commit comments

Comments
 (0)