Skip to content

Commit 5758700

Browse files
committed
Tweak improveReadOnly
Widen to cap.rd only if parent type does not extend Mutable.
1 parent dfd3c81 commit 5758700

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ class CheckCaptures extends Recheck, SymTransformer:
15841584
case actual @ CapturingType(parent, refs)
15851585
if parent.derivesFrom(defn.Caps_Mutable)
15861586
&& expected.isValueType
1587-
&& !expected.isMutableType
1587+
&& !expected.derivesFromMutable
15881588
&& !expected.isSingleton
15891589
&& !expected.isBoxedCapturing =>
15901590
actual.derivedCapturingType(parent, refs.readOnly)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrude-mut.scala:9:8 ------------------------------
22
9 | a = a1 // error
33
| ^^
4-
| Found: A^{a1.rd}
5-
| Required: A^
4+
| Found: (a1 : A^)
5+
| Required: A^²
66
|
7-
| where: ^ refers to a fresh root capability in the type of variable a
7+
| where: ^ refers to a fresh root capability created in value a1 when constructing mutable A
8+
| ^² refers to a fresh root capability in the type of variable a
89
|
910
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)