Skip to content

Commit

Permalink
Bring back RefiningVar
Browse files Browse the repository at this point in the history
We might want to treat it specially since a RefiningVar should ideally be closed for
further additions when the constructor has been analyzed.
  • Loading branch information
odersky committed Jun 27, 2024
1 parent 38cf302 commit dd4a60a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ object CaptureSet:
override def toString = s"Var$id$elems"
end Var

/** Variables that represent refinements of class parameters can have the universal
* capture set, since they represent only what is the result of the constructor.
* Test case: Without that tweak, logger.scala would not compile.
*/
class RefiningVar(owner: Symbol)(using Context) extends Var(owner):
override def disallowRootCapability(handler: () => Context ?=> Unit)(using Context) = this

/** A variable that is derived from some other variable via a map or filter. */
abstract class DerivedVar(owner: Symbol, initialElems: Refs)(using @constructorOnly ctx: Context)
extends Var(owner, initialElems):
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
val getterType =
mapInferred(refine = false)(tp.memberInfo(getter)).strippedDealias
RefinedType(core, getter.name,
CapturingType(getterType,
new CaptureSet.Var(ctx.owner):
override def disallowRootCapability(handler: () => Context ?=> Unit)(using Context) = this
))
CapturingType(getterType, new CaptureSet.RefiningVar(ctx.owner)))
.showing(i"add capture refinement $tp --> $result", capt)
else
core
Expand Down

0 comments on commit dd4a60a

Please sign in to comment.