diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index 74279197d45d..714f769dacd9 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -738,20 +738,20 @@ class CheckCaptures extends Recheck, SymTransformer: * the innermost capturing type. The outer capture annotations can be * reconstructed with the returned function. */ - def destructCapturingType(tp: Type, reconstruct: Type => Type = x => x): ((Type, CaptureSet, Boolean), Type => Type) = + def destructCapturingType(tp: Type, reconstruct: Type => Type = x => x): (Type, CaptureSet, Boolean, Type => Type) = tp.dealias match case tp @ CapturingType(parent, cs) => if parent.dealias.isCapturingType then destructCapturingType(parent, res => reconstruct(tp.derivedCapturingType(res, cs))) else - ((parent, cs, tp.isBoxed), reconstruct) + (parent, cs, tp.isBoxed, reconstruct) case actual => - ((actual, CaptureSet(), false), reconstruct) + (actual, CaptureSet(), false, reconstruct) def adapt(actual: Type, expected: Type, covariant: Boolean): Type = trace(adaptInfo(actual, expected, covariant), recheckr, show = true) { if expected.isInstanceOf[WildcardType] then actual else - val ((parent, cs, actualIsBoxed), recon) = destructCapturingType(actual) + val (parent, cs, actualIsBoxed, recon) = destructCapturingType(actual) val needsAdaptation = actualIsBoxed != expected.isBoxedCapturing val insertBox = needsAdaptation && covariant != actualIsBoxed diff --git a/tests/neg-custom-args/captures/PENDING-box-override.scala b/tests/neg-custom-args/captures/PENDING-box-override.scala new file mode 100644 index 000000000000..efb7bfaea1ac --- /dev/null +++ b/tests/neg-custom-args/captures/PENDING-box-override.scala @@ -0,0 +1,18 @@ +abstract class A[X]: + def foo(x: X): X + +class IO +class C +def test(io: {*} IO) = + class B extends A[{io} C]: // error, but should work + override def foo(x: {io} C): {io} C = ??? + +/* -- Error: box-override.scala:7:8 ----------------------------------------------- +7 | class B extends A[{io} C]: + | ^ + |class B needs to be abstract, since def foo(x: X): X in class A is not defined + |(Note that + | parameter X in def foo(x: X): X in class A does not match + | parameter {io} C in override def foo(x: {io} C): {io} C in class B + | ) +*/