Skip to content

Commit

Permalink
Merge pull request #13655 from dotty-staging/lazy-list-essays
Browse files Browse the repository at this point in the history
Include capture sets of methods in enclosing class
  • Loading branch information
odersky authored Oct 2, 2021
2 parents 06f83ce + 0feb5d7 commit 9a63b05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ class CheckCaptures extends Recheck:
case ref: TermRef => ref.symbol.enclosure != ownEnclosure
case _ => true
}
checkSubset(targetSet, curEnv.captured, pos)
def includeIn(env: Env) =
capt.println(i"Include call capture $targetSet in ${env.owner}")
checkSubset(targetSet, env.captured, pos)
includeIn(curEnv)
if curEnv.owner.isTerm && curEnv.outer.owner.isClass then
includeIn(curEnv.outer)

def includeBoxedCaptures(tp: Type, pos: SrcPos)(using Context): Unit =
if curEnv.isOpen then
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-custom-args/captures/nestedclass.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/nestedclass.scala:15:15 ----------------------------------
15 | val xsc: C = xs // error
| ^^
| Found: (xs : {cap1} C)
| Required: C

longer explanation available when compiling with `-explain`
15 changes: 15 additions & 0 deletions tests/neg-custom-args/captures/nestedclass.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CC
type Cap = {*} CC

abstract class C:
def head: String

def test(cap1: Cap, cap2: Cap) =
def f(x: String): String = if cap1 == cap1 then "" else "a"
def g(x: String): String = if cap2 == cap2 then "" else "a"

val xs =
class Cimpl extends C:
def head = f("")
new Cimpl
val xsc: C = xs // error

0 comments on commit 9a63b05

Please sign in to comment.