@@ -39,7 +39,18 @@ object Checking {
3939 safePromoted : mutable.Set [Potential ], // Potentials that can be safely promoted
4040 env : Env
4141 ) {
42- def withOwner (sym : Symbol ): State = copy(env = env.withOwner(sym))
42+ def withOwner [T ](sym : Symbol )(op : State ?=> T ): T =
43+ val state = this .copy(env = env.withOwner(sym))
44+ val res = op(using state)
45+ this .visited = state.visited
46+ res
47+
48+
49+ def visit [T ](eff : Effect )(op : State ?=> T ): T =
50+ val state : State = this .copy(path = path :+ eff.source, visited = this .visited + eff)
51+ val res = op(using state)
52+ this .visited = state.visited
53+ res
4354
4455 def test (op : State ?=> Errors ): Errors = {
4556 val savedVisited = visited
@@ -58,15 +69,14 @@ object Checking {
5869 traceIndented(" Already checked " + eff.show, init)
5970 Errors .empty
6071 }
61- else {
62- state.visited = state.visited + eff
63- val state2 : State = state.copy(path = state.path :+ eff.source)
64- eff match {
65- case eff : Promote => Checking .checkPromote (eff)( using state2 )
66- case eff : FieldAccess => Checking .checkFieldAccess (eff)( using state2 )
67- case eff : MethodCall => Checking .checkMethodCall(eff)( using state2)
72+ else
73+ state.visit( eff) {
74+ eff match {
75+ case eff : Promote => Checking .checkPromote(eff)
76+ case eff : FieldAccess => Checking .checkFieldAccess (eff)
77+ case eff : MethodCall => Checking .checkMethodCall (eff)
78+ }
6879 }
69- }
7080 }
7181 }
7282
@@ -118,11 +128,11 @@ object Checking {
118128 def checkConstructor (ctor : Symbol , tp : Type , source : Tree )(using state : State ): Unit = traceOp(" checking " + ctor.show, init) {
119129 val cls = ctor.owner
120130 val classDef = cls.defTree
121- if (! classDef.isEmpty) {
122- given State = state.withOwner(cls)
123- if (ctor.isPrimaryConstructor) checkClassBody(classDef.asInstanceOf [TypeDef ])
124- else checkSecondaryConstructor(ctor)
125- }
131+ if (! classDef.isEmpty)
132+ state.withOwner(cls) {
133+ if (ctor.isPrimaryConstructor) checkClassBody(classDef.asInstanceOf [TypeDef ])
134+ else checkSecondaryConstructor(ctor)
135+ }
126136 }
127137
128138 def checkSecondaryConstructor (ctor : Symbol )(using state : State ): Unit = traceOp(" checking " + ctor.show, init) {
0 commit comments