Skip to content

Commit ab26c44

Browse files
Fix wrong scope handling
1 parent 6685a92 commit ab26c44

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

effekt/jvm/src/test/scala/effekt/core/TestRenamer.scala

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package effekt.core
22

33
import effekt.{Template, core, symbols}
4-
import effekt.context.Context
5-
import effekt.core.Type.{PromptSymbol, ResumeSymbol}
64

75
/**
86
* Freshens bound names in a given term for tests.
@@ -52,13 +50,12 @@ class TestRenamer(names: Names = Names(Map.empty)) extends core.Tree.Rewrite {
5250
case bnds if bnds.contains(id) => bnds(id)
5351
}.getOrElse {
5452
scopes match {
55-
case Nil =>
56-
id
57-
case head :: tail => {
53+
case Nil => id
54+
case _ =>
5855
val freshId = freshIdFor(id)
59-
scopes = (head + (id -> freshId)) :: tail
56+
val updatedLast = scopes.last + (id -> freshId)
57+
scopes = scopes.init :+ updatedLast
6058
freshId
61-
}
6259
}
6360
}
6461
}
@@ -188,17 +185,11 @@ class TestRenamer(names: Names = Names(Map.empty)) extends core.Tree.Rewrite {
188185
}
189186

190187
override def rewrite(p: Property) = p match {
191-
case Property(id: Id, tpe: BlockType) =>
192-
withBinding(id) {
193-
Property(rewrite(id), rewrite(tpe))
194-
}
188+
case Property(id: Id, tpe: BlockType) => Property(rewrite(id), rewrite(tpe))
195189
}
196190

197191
override def rewrite(f: Field) = f match {
198-
case Field(id, tpe) =>
199-
withBinding(id) {
200-
Field(rewrite(id), rewrite(tpe))
201-
}
192+
case Field(id, tpe) => Field(rewrite(id), rewrite(tpe))
202193
}
203194

204195
override def rewrite(b: BlockType): BlockType = b match {
@@ -229,15 +220,11 @@ class TestRenamer(names: Names = Names(Map.empty)) extends core.Tree.Rewrite {
229220
}
230221

231222
override def rewrite(b: BlockParam): BlockParam = b match {
232-
case BlockParam(id, tpe, capt) => withBinding(id) {
233-
BlockParam(rewrite(id), rewrite(tpe), rewrite(capt))
234-
}
223+
case BlockParam(id, tpe, capt) => BlockParam(rewrite(id), rewrite(tpe), rewrite(capt))
235224
}
236225

237226
override def rewrite(v: ValueParam): ValueParam = v match {
238-
case ValueParam(id, tpe) => withBinding(id) {
239-
ValueParam(rewrite(id), rewrite(tpe))
240-
}
227+
case ValueParam(id, tpe) => ValueParam(rewrite(id), rewrite(tpe))
241228
}
242229

243230
def apply(m: core.ModuleDecl): core.ModuleDecl =

0 commit comments

Comments
 (0)