Skip to content

Commit e15bfc4

Browse files
committed
Add List encoding test
1 parent 0341f7f commit e15bfc4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ object CaptureSet:
8585
val collect = new TypeAccumulator[Refs]:
8686
var localBinders: SimpleIdentitySet[BindingType] = SimpleIdentitySet.empty
8787
var seenLazyRefs: SimpleIdentitySet[LazyRef] = SimpleIdentitySet.empty
88-
def apply(elems: Refs, tp: Type): Refs = trace(i"capt $elems, $tp", show = true) {
88+
def apply(elems: Refs, tp: Type): Refs = trace(i"capt $elems, $tp", capt, show = true) {
8989
tp match
9090
case tp: NamedType =>
9191
if variance < 0 then elems
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type Top = Any retains *
2+
class Cap extends Retains[*]
3+
4+
type Op[T <: Top, C <: Top] =
5+
((v: T) => ((s: C) => C) retains *) retains *
6+
7+
type List[T <: Top] =
8+
[C <: Top] => (op: Op[T, C]) => ((s: C) => C) retains op.type
9+
10+
def nil[T <: Top]: List[T] =
11+
[C <: Top] => (op: Op[T, C]) => (s: C) => s
12+
13+
def cons[T <: Top](hd: T, tl: List[T]): List[T] =
14+
[C <: Top] => (op: Op[T, C]) => (s: C) => op(hd)(tl(op)(s))
15+
16+
def foo(c: Cap) =
17+
def f(x: String retains c.type, y: String retains c.type) =
18+
cons(x, cons(y, nil))
19+
def g(x: String retains c.type, y: Any) =
20+
cons(x, cons(y, nil))
21+
def h(x: String, y: Any retains c.type) =
22+
cons(x, cons(y, nil))

0 commit comments

Comments
 (0)