Skip to content

Commit d76dbe4

Browse files
committed
Fix unbox operation called from unsafeUnbox
1 parent f9c9a03 commit d76dbe4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,16 @@ extension (tp: Type)
9696
/** Is the boxedCaptureSet of this type nonempty? */
9797
def isBoxedCapturing(using Context) = !tp.boxedCaptureSet.isAlwaysEmpty
9898

99-
/** If this type is a boxed capturing type, its unboxed version */
100-
def unbox(using Context): Type = tp match
99+
/** If this type is a boxed capturing type, its unboxed version
100+
* If it is a TermRef of boxed capturing type, an unboxed capturing
101+
* type capturing the TermRef.
102+
*/
103+
def unbox(using Context): Type = tp.widenDealias match
101104
case tp @ CapturingType(parent, refs) if tp.isBoxed =>
102-
CapturingType(parent, refs, boxed = false)
105+
val refs1 = tp match
106+
case ref: CaptureRef if ref.isTracked => ref.singletonCaptureSet
107+
case _ => refs
108+
CapturingType(parent, refs1, boxed = false)
103109
case _ =>
104110
tp
105111

tests/pos-custom-args/captures/vars1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ type ErrorHandler = (Int, String) => Unit
33

44
var defaultIncompleteHandler: ErrorHandler = ???
55
var incompleteHandler: ErrorHandler = defaultIncompleteHandler
6-
//val x = incompleteHandler.unsafeUnbox
7-
8-
6+
val x = incompleteHandler.unsafeUnbox
7+
val _ : ErrorHandler = x
8+
val _ = x(1, "a")

0 commit comments

Comments
 (0)