Skip to content

Commit ce90f47

Browse files
committed
Drop isOfNestedMethod exception in normal mode
It's hard to generalie this to late use checking. And it does not add anything fundamental.
1 parent 42fdd76 commit ce90f47

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,13 @@ class CheckCaptures extends Recheck, SymTransformer:
424424
else
425425
i"\nof the enclosing ${owner.showLocated}"
426426

427-
/** Does the given environment belong to a method that is (a) nested in a term
427+
/** Under deferredReaches:
428+
* Does the given environment belong to a method that is (a) nested in a term
428429
* and (b) not the method of an anonymous function?
429430
*/
430431
def isOfNestedMethod(env: Env | Null)(using Context) =
431-
env != null
432+
ccConfig.deferredReaches
433+
&& env != null
432434
&& env.owner.is(Method)
433435
&& env.owner.owner.isTerm
434436
&& !env.owner.isAnonymousFunction
@@ -537,7 +539,7 @@ class CheckCaptures extends Recheck, SymTransformer:
537539
isVisible
538540
checkSubset(included, env.captured, tree.srcPos, provenance(env))
539541
capt.println(i"Include call or box capture $included from $cs in ${env.owner} --> ${env.captured}")
540-
if !isOfNestedMethod(env) then
542+
if !isOfNestedMethod(env) || true then
541543
recur(included, nextEnvToCharge(env, !_.owner.isStaticOwner), env)
542544
// Don't propagate out of methods inside terms. The use set of these methods
543545
// will be charged when that method is called.

tests/neg-custom-args/captures/method-uses.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ def test(xs: List[() => Unit]) =
22
xs.head // error
33

44
def foo =
5-
xs.head // ok
5+
xs.head // error, ok under deferredReaches
66
def bar() =
7-
xs.head // ok
7+
xs.head // error, ok under deferredReaches
88

99
class Foo:
1010
println(xs.head) // error, but could be OK
@@ -14,7 +14,7 @@ def test(xs: List[() => Unit]) =
1414
Foo() // OK, but could be error
1515

1616
def test2(xs: List[() => Unit]) =
17-
def foo = xs.head // ok
17+
def foo = xs.head // error, ok under deferredReaches
1818
()
1919

2020
def test3(xs: List[() => Unit]): () ->{xs*} Unit = () =>

0 commit comments

Comments
 (0)