@@ -39,7 +39,18 @@ object Checking {
39
39
safePromoted : mutable.Set [Potential ], // Potentials that can be safely promoted
40
40
env : Env
41
41
) {
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
43
54
44
55
def test (op : State ?=> Errors ): Errors = {
45
56
val savedVisited = visited
@@ -58,15 +69,14 @@ object Checking {
58
69
traceIndented(" Already checked " + eff.show, init)
59
70
Errors .empty
60
71
}
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
+ }
68
79
}
69
- }
70
80
}
71
81
}
72
82
@@ -118,11 +128,11 @@ object Checking {
118
128
def checkConstructor (ctor : Symbol , tp : Type , source : Tree )(using state : State ): Unit = traceOp(" checking " + ctor.show, init) {
119
129
val cls = ctor.owner
120
130
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
+ }
126
136
}
127
137
128
138
def checkSecondaryConstructor (ctor : Symbol )(using state : State ): Unit = traceOp(" checking " + ctor.show, init) {
0 commit comments