Skip to content

Commit 801d0d3

Browse files
committed
Disable special treatment of eta expansions in recheckClosure
1 parent 4dfd65f commit 801d0d3

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ object ccConfig:
3333
*/
3434
inline val optimizedRefinements = false
3535

36+
/** If enabled, use a special path in recheckClosure for closures
37+
* that are eta expansions. This can improve some error messages but
38+
* currently leads to unsoundess for handlng reach capabilities.
39+
* TODO: The unsoundness needs followin up.
40+
*/
41+
inline val handleEtaExpansionsSpecially = false
42+
3643
/** If true, use existential capture set variables */
3744
def useExistentials(using Context) =
3845
Feature.sourceVersion.stable.isAtLeast(SourceVersion.`3.5`)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class CheckCaptures extends Recheck, SymTransformer:
628628
// Constrain closure's parameters and result from the expected type before
629629
// rechecking the body.
630630
val res = recheckClosure(expr, pt, forceDependent = true)
631-
if !isEtaExpansion(mdef) then
631+
if !(isEtaExpansion(mdef) && ccConfig.handleEtaExpansionsSpecially) then
632632
// If closure is an eta expanded method reference it's better to not constrain
633633
// its internals early since that would give error messages in generated code
634634
// which are less intelligible.

tests/neg-custom-args/captures/effect-swaps-explicit.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
-- Error: tests/neg-custom-args/captures/effect-swaps-explicit.scala:68:15 ---------------------------------------------
2626
68 | Result.make: //lbl ?=> // error, escaping label from Result
2727
| ^^^^^^^^^^^
28-
|local reference contextual$9 from (using contextual$9: boundary.Label[Result[box Future[box T^?]^{fr, contextual$9}, box E^?]]^):
29-
| box Future[box T^?]^{fr, contextual$9} leaks into outer capture set of type parameter T of method make in object Result
28+
|local reference contextual$9 from (using contextual$9: boundary.Label[Result[box Future[box T^?]^{fr, contextual$9, contextual$9}, box E^?]]^):
29+
| box Future[box T^?]^{fr, contextual$9, contextual$9} leaks into outer capture set of type parameter T of method make in object Result

tests/neg-custom-args/captures/levels.check

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
| that type captures the root capability `cap`.
66
| This is often caused by a local capability in an argument of constructor Ref
77
| leaking as part of its result.
8-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/levels.scala:24:11 ---------------------------------------
8+
-- Error: tests/neg-custom-args/captures/levels.scala:24:11 ------------------------------------------------------------
99
24 | r.setV(g) // error
1010
| ^
11-
| Found: box (x: String) ->{cap3} String
12-
| Required: box (x$0: String) ->? String
11+
| reference (cap3 : CC^) is not included in the allowed capture set ? of value r
1312
|
1413
| Note that reference (cap3 : CC^), defined in method scope
1514
| cannot be included in outer capture set ? of value r
16-
|
17-
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/vars-simple.check

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
| since at least one of their capture sets contains the root capability `cap`
99
|
1010
| longer explanation available when compiling with `-explain`
11-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars-simple.scala:16:8 -----------------------------------
11+
-- Error: tests/neg-custom-args/captures/vars-simple.scala:16:8 --------------------------------------------------------
1212
16 | a = g // error
1313
| ^
14-
| Found: box (x: String) ->{cap3} String
15-
| Required: box (x: String) ->{cap1, cap2} String
16-
|
17-
| longer explanation available when compiling with `-explain`
14+
| reference (cap3 : Cap) is not included in the allowed capture set {cap1, cap2}
15+
| of an enclosing function literal with expected type box String ->{cap1, cap2} String
1816
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars-simple.scala:17:12 ----------------------------------
1917
17 | b = List(g) // error
2018
| ^^^^^^^

tests/neg-custom-args/captures/vars.check

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
|
66
| Note that reference (cap3 : Cap), defined in method scope
77
| cannot be included in outer capture set {cap1} of variable a
8-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:25:8 ------------------------------------------
8+
-- Error: tests/neg-custom-args/captures/vars.scala:25:8 ---------------------------------------------------------------
99
25 | a = g // error
1010
| ^
11-
| Found: (x: String) ->{cap3} String
12-
| Required: (x$0: String) ->{cap1} String
11+
| reference (cap3 : Cap) is not included in the allowed capture set {cap1} of variable a
1312
|
1413
| Note that reference (cap3 : Cap), defined in method scope
1514
| cannot be included in outer capture set {cap1} of variable a
16-
|
17-
| longer explanation available when compiling with `-explain`
1815
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:27:12 -----------------------------------------
1916
27 | b = List(g) // error
2017
| ^^^^^^^

0 commit comments

Comments
 (0)