Sharpen range approximation for applied types with capture set ranges #16261
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.
This is a stopgap to avoid approximating the core type to Nothing. It can probably be dropped once we have capture set ranges that we can keep as inference results. The problem is, what should be the approximation of the range
where the type constructor
C
is non-variant? If the variance of the enclosing map is positive, this isC[? >: {cs1} A <: {cs2} A]
, which is a supertype of both range end pointsC[{cs1} A]
andC[{cs2} A]
. But if the variance is negative, we would normally fall back toNothing
, since that is the only known subtype of both range end points. This reasoning seems too strict for capture checking. In a sense, we have already inferredC[A]
before; now we just need to find out what the set should be. What we are after is a notion of a capture set range. I.e. something likewith the meaning that the capture set of
C
is an unknown set betweencs1
andcs2
. We don't have that abstraction yet, so for now we approximate by the bounds, which avoids the failures, even though its soundness status is currently a bit unclear.