Skip to content

Commit 850d1c1

Browse files
committed
Include capture sets of methods in enclosing class
1 parent d2a5e8d commit 850d1c1

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,12 @@ class CheckCaptures extends Recheck:
263263
case ref: TermRef => ref.symbol.enclosure != ownEnclosure
264264
case _ => true
265265
}
266-
checkSubset(targetSet, curEnv.captured, pos)
266+
def includeIn(env: Env) =
267+
capt.println(i"Include call capture $targetSet in ${env.owner}")
268+
checkSubset(targetSet, env.captured, pos)
269+
includeIn(curEnv)
270+
if curEnv.owner.isTerm && curEnv.outer.owner.isClass then
271+
includeIn(curEnv.outer)
267272

268273
def includeBoxedCaptures(tp: Type, pos: SrcPos)(using Context): Unit =
269274
if curEnv.isOpen then
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/nestedclass.scala:15:15 ----------------------------------
2+
15 | val xsc: C = xs // error
3+
| ^^
4+
| Found: (xs : {cap1} C)
5+
| Required: C
6+
7+
longer explanation available when compiling with `-explain`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class CC
2+
type Cap = {*} CC
3+
4+
abstract class C:
5+
def head: String
6+
7+
def test(cap1: Cap, cap2: Cap) =
8+
def f(x: String): String = if cap1 == cap1 then "" else "a"
9+
def g(x: String): String = if cap2 == cap2 then "" else "a"
10+
11+
val xs =
12+
class Cimpl extends C:
13+
def head = f("")
14+
new Cimpl
15+
val xsc: C = xs // error

0 commit comments

Comments
 (0)