Skip to content

Fix i19315: avoid calling addOuterRefs when the actual type is box-adapted #19323

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

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,13 @@ class CheckCaptures extends Recheck, SymTransformer:
* where local capture roots are instantiated to root variables.
*/
override def checkConformsExpr(actual: Type, expected: Type, tree: Tree, addenda: Addenda)(using Context): Type =
val expected1 = alignDependentFunction(addOuterRefs(expected, actual), actual.stripCapturing)
var expected1 = alignDependentFunction(expected, actual.stripCapturing)
val actualBoxed = adaptBoxed(actual, expected1, tree.srcPos)
//println(i"check conforms $actualBoxed <<< $expected1")

if actualBoxed eq actual then
// Only `addOuterRefs` when there is no box adaptation
expected1 = addOuterRefs(expected1, actual)
if isCompatible(actualBoxed, expected1) then
if debugSuccesses then tree match
case Ident(_) =>
Expand Down
15 changes: 15 additions & 0 deletions tests/neg-custom-args/captures/cc-selftype-unsound.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import language.experimental.captureChecking
trait Logger
case class Boxed[T](unbox: T)

// a horrible function, but it typechecks
def magic(l: Logger^): Logger =
class Foo:
def foo: Boxed[Logger^{this}] =
// for the following line to typecheck
// the capture checker assumes {l} <: {this}
Boxed[Logger^{this}](l) // error
val x = new Foo
val y = x.foo.unbox // y: Logger^{x}
val z: Logger = y // now the capability becomes pure
z