Fix i19315: avoid calling addOuterRefs
when the actual type is box-adapted
#19323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #19315.
The unsound code:
The
magic
function typechecks before this fix. It casts a capability to a pure value, which is clearly unsound. The crux of the problem isBoxed[Logger^{this}](l)
, which relies on the subcapturing relation{l} <: {this}
enabled by the trick implementedaddOuterRefs
.addOuterRefs
augment a capture set that contains a self reference (like{this}
) with all outer references reachable fromthis
. In this case, the augmented set is{this, l}
. The reasoning is that, any captured outer references in the class can be rewritten into a field, thus being a subcapture of{this}
:But the problem with this unsound example is that, the reference to
l
is boxed, sol
is not captured by the class. Therefore, the above rewriting mismatches with the actual situation.This PR proposes a simple fix, which simply disable
addOuterRefs
when box adaptation happens. This is of course imprecise, but all tests pass with this fix.