Skip to content

Commit dd4a60a

Browse files
committed
Bring back RefiningVar
We might want to treat it specially since a RefiningVar should ideally be closed for further additions when the constructor has been analyzed.
1 parent 38cf302 commit dd4a60a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ object CaptureSet:
634634
override def toString = s"Var$id$elems"
635635
end Var
636636

637+
/** Variables that represent refinements of class parameters can have the universal
638+
* capture set, since they represent only what is the result of the constructor.
639+
* Test case: Without that tweak, logger.scala would not compile.
640+
*/
641+
class RefiningVar(owner: Symbol)(using Context) extends Var(owner):
642+
override def disallowRootCapability(handler: () => Context ?=> Unit)(using Context) = this
643+
637644
/** A variable that is derived from some other variable via a map or filter. */
638645
abstract class DerivedVar(owner: Symbol, initialElems: Refs)(using @constructorOnly ctx: Context)
639646
extends Var(owner, initialElems):

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
193193
val getterType =
194194
mapInferred(refine = false)(tp.memberInfo(getter)).strippedDealias
195195
RefinedType(core, getter.name,
196-
CapturingType(getterType,
197-
new CaptureSet.Var(ctx.owner):
198-
override def disallowRootCapability(handler: () => Context ?=> Unit)(using Context) = this
199-
))
196+
CapturingType(getterType, new CaptureSet.RefiningVar(ctx.owner)))
200197
.showing(i"add capture refinement $tp --> $result", capt)
201198
else
202199
core

0 commit comments

Comments
 (0)