Skip to content

Commit e0c3a02

Browse files
committed
Refactor CaptureParam Flag Set
1 parent cc28c91 commit e0c3a02

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,13 @@ object Flags {
433433
/** A denotation that is valid in all run-ids */
434434
val (Permanent @ _, _, _) = newFlags(61, "<permanent>")
435435

436-
/** Symbol is a constructor proxy (either companion, or apply method) */
436+
/** A phantom symbol made up by the compiler to achieve special typing rules.
437+
* Phantom symbols cannot be used as regular values, and will be erased after erasure phase.
438+
* - For constructor proxies (companion or apply method).
439+
* - For dummy capture parameters in capture sets (variables or fields).
440+
*/
437441
val (PhantomSymbol @ _, _, _) = newFlags(62, "<phantom symbol>") // (could be merged with Lifted)
438442

439-
val CaptureParam = PhantomSymbol
440-
441443
// --------- Combined Flag Sets and Conjunctions ----------------------
442444

443445
/** All possible flags */
@@ -569,6 +571,7 @@ object Flags {
569571
val ContravariantLocal: FlagSet = Contravariant | Local // A contravariant type parameter
570572
val EffectivelyErased = PhantomSymbol | Erased
571573
val ConstructorProxyModule: FlagSet = PhantomSymbol | Module
574+
val CaptureParam: FlagSet = PhantomSymbol | StableRealizable | Synthetic
572575
val DefaultParameter: FlagSet = HasDefault | Param // A Scala 2x default parameter
573576
val DeferredInline: FlagSet = Deferred | Inline
574577
val DeferredMethod: FlagSet = Deferred | Method

compiler/src/dotty/tools/dotc/core/NamerOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ object NamerOps:
324324
*/
325325
def addDummyTermCaptureParam(param: Symbol)(using Context): Unit =
326326
val name = param.name.toTermName
327-
val flags = (param.flagsUNSAFE & AccessFlags).toTermFlags | CaptureParam | StableRealizable | Synthetic
327+
val flags = (param.flagsUNSAFE & AccessFlags).toTermFlags | CaptureParam
328328
val dummy = newSymbol(param.owner, name, flags, param.typeRef)
329329
typr.println(i"Adding dummy term symbol $dummy for $param, flags = $flags")
330330
ctx.enter(dummy)

compiler/src/dotty/tools/dotc/core/SymUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SymUtils:
9191
self.is(Synthetic) && self.infoOrCompleter.typeSymbol == defn.CBCompanion
9292

9393
def isDummyCaptureParam(using Context): Boolean =
94-
self.is(Synthetic) && self.is(CaptureParam) && !(self.isClass || self.is(Method))
94+
self.isAllOf(CaptureParam) && !(self.isClass || self.is(Method))
9595

9696
/** Is this a case class for which a product mirror is generated?
9797
* Excluded are value classes, abstract classes and case classes with more than one

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25332533

25342534
def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(using Context): Tree = {
25352535
val ref1 = typedExpr(tree.ref, SingletonTypeProto)
2536-
if ctx.mode.is(Mode.InCaptureSet) && ref1.symbol.is(Flags.CaptureParam) then
2536+
if ctx.mode.is(Mode.InCaptureSet) && ref1.symbol.isDummyCaptureParam then
25372537
// When a dummy term capture variable is found, it is replaced with
25382538
// the corresponding type references (stored in the underling types).
25392539
return Ident(ref1.tpe.widen.asInstanceOf[TypeRef]).withSpan(tree.span)

0 commit comments

Comments
 (0)