Skip to content
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

Fix ctx implicits under case unapplySeq #21748

Merged
merged 1 commit into from
Oct 27, 2024
Merged

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Oct 10, 2024

A case class with a varargs has a unapplySeq extractor instead of
unapply. When we type an unapply, in typedUnapply, we first look for
unapply methods before unapplySeq methods. But when searching for
unapply, if a class method isn't found, then an extension method is
looked for, which causes context implicits to be cached. The bindings
from a pattern (such as from an unapply or unapplySeq extractor) are
added to the scope in indexPattern. But Context's implicitCache
doesn't account for the scope changing.

I opted for giving the body its own scope context, rather than making
indexPattern reset the context implicits cache.

Fixes #21742

A case class with a varargs has a unapplySeq extractor instead of
unapply.  When we type an unapply, in typedUnapply, we first look for
unapply methods before unapplySeq methods.  But when searching for
unapply, if a class method isn't found, then an extension method is
looked for, which causes context implicits to be cached.  The bindings
from a pattern (such as from an unapply or unapplySeq extractor) are
added to the context in indexPattern.  But Context's `implicitCache`
doesn't account for the scope changing.

I opted for giving the body its own scope context, rather than making
indexPattern reset the context implicits cache.
@dwijnand dwijnand marked this pull request as ready for review October 10, 2024 17:40
@dwijnand dwijnand requested a review from odersky October 10, 2024 17:40
@odersky odersky merged commit dd37f07 into scala:main Oct 27, 2024
28 checks passed
@dwijnand dwijnand deleted the given-Int-varargs branch October 28, 2024 11:44
@WojciechMazur WojciechMazur added this to the 3.6.3 milestone Dec 9, 2024
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.

pattern matching with given and vararg fails
3 participants