Skip to content

Commit af36d6e

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 a5c26cd commit af36d6e

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
@@ -427,11 +427,13 @@ class CheckCaptures extends Recheck, SymTransformer:
427427
else
428428
i"\nof the enclosing ${owner.showLocated}"
429429

430-
/** Does the given environment belong to a method that is (a) nested in a term
430+
/** Under deferredReaches:
431+
* Does the given environment belong to a method that is (a) nested in a term
431432
* and (b) not the method of an anonymous function?
432433
*/
433434
def isOfNestedMethod(env: Env | Null)(using Context) =
434-
env != null
435+
ccConfig.deferredReaches
436+
&& env != null
435437
&& env.owner.is(Method)
436438
&& env.owner.owner.isTerm
437439
&& !env.owner.isAnonymousFunction
@@ -540,7 +542,7 @@ class CheckCaptures extends Recheck, SymTransformer:
540542
isVisible
541543
checkSubset(included, env.captured, tree.srcPos, provenance(env))
542544
capt.println(i"Include call or box capture $included from $cs in ${env.owner} --> ${env.captured}")
543-
if !isOfNestedMethod(env) then
545+
if !isOfNestedMethod(env) || true then
544546
recur(included, nextEnvToCharge(env, !_.owner.isStaticOwner), env)
545547
// Don't propagate out of methods inside terms. The use set of these methods
546548
// 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)