Skip to content

SI-9498 Avoid caching bug with pattern type variables #4774

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 2 commits into from
Oct 5, 2015

Conversation

retronym
Copy link
Member

Review by @SethTisue and @adriaanm

Typechecking a pattern that defines a pattern type variable
initially assigns abstract type symbol with open type bounds.

Later on, pattern type inference kicks in to sharpen the type
of the variable based on constraints imposed by the expected
type (ie, the type of scrutinee of the pattern.)

However, before inference does this, a `TypeRef` to the abstract
type symbol can be queried for its base type with respect to some
class, which leads to it populating an internal cache. This cache
becomes stale when the underlying symbol has its type mutated.

The repercussions of this meant that a subsequent call to `baseType`
gave the wrong result (`NoType`), which lead to an `asSeenFrom`
operation to miss out of substitution of a type variable. Note the
appearance of `A` in the old type errors in the enclosed test case.

This commit takes an approach similar to 286dafb to invalidate
caches after the mutation. I've routed both bandaids through the
same first aid kit: I'm sure over time we'll add additional calls
to this method, and additional cache invalidations within it.
I found another spot where I had previously needed to manually
invalidate a TypeRef cache, and modified that to route through
the newly added `invalidatedCaches`.

`invalidatedCaches` now invalidates all the other caches I could
find in our types of types. I opted for a non-OO approach here,
as we've got a fairly intricate lattice of traits in place that
define caches, and I didn't have the stomach for adding a polymorphic
`Type::invalidatedCaches` with the the right sprinkling over overrides
and super calls.
@lrytz
Copy link
Member

lrytz commented Oct 5, 2015

LGTM

lrytz added a commit that referenced this pull request Oct 5, 2015
SI-9498 Avoid caching bug with pattern type variables
@lrytz lrytz merged commit 3d15ba0 into scala:2.12.x Oct 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants