Skip to content

A problematic test showing interaction of boxing and inheritance #16415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/neg-custom-args/captures/PENDING-box-override.scala
Original file line number Diff line number Diff line change
@@ -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
| )
*/