Skip to content

Commit f4823f3

Browse files
Add wellformedness check for type of var ... in ... (#961)
Fixes #919 by adding a wellformedness check as suggested [here](#919 (comment)). Resulting error message: <img width="1272" alt="Screenshot 2025-04-25 at 14 27 57" src="https://github.com/user-attachments/assets/e81597a0-602e-4868-a5fd-7ecc1e4e3562" />
1 parent 80bfde7 commit f4823f3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

effekt/shared/src/main/scala/effekt/typer/Wellformedness.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ object Wellformedness extends Phase[Typechecked, Typechecked], Visit[WFContext]
315315
val boundTypes = tps.map(_.symbol.asTypeParam).toSet[TypeVar]
316316
val boundCapts = bps.map(_.id.symbol.asBlockParam.capture).toSet
317317
binding(types = boundTypes, captures = boundCapts) { bodies.foreach(query) }
318+
319+
case tree @ source.RegDef(id, annot, region, init) =>
320+
wellformed(Context.typeOf(id.symbol), tree, pp" inferred as type of region-allocated variable")
321+
query(init)
318322
}
319323

320324
// Can only compute free capture on concrete sets

examples/neg/issue919.effekt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
effect tick(): Unit
2+
3+
def main() = {
4+
region r {
5+
var k in r = box { () } // ERROR tick escapes
6+
try {
7+
k = box { do tick() }
8+
} with tick { () => () }
9+
k()
10+
}
11+
}

0 commit comments

Comments
 (0)