Skip to content

Scala2Unpickler: Don't trust the owner field of tparams #12660

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
Jun 2, 2021

Conversation

smarter
Copy link
Member

@smarter smarter commented May 31, 2021

When a type parameter of a class external to the current pickle is
referenced, Scala 2 will sometimes pickle it as if it was a type
parameter of the current class. When we unpickle such a type parameter
on our side, we enter it in the class, this leads the compiler to
believe the class has more type parameters than it actually has. This
doesn't happen in Scala 2 itself because it never enters unpickled type
parameters in the class that owns them (it must be recreating them in
some way, but I don't know how).

It would be interesting to dig deeper to understand exactly how Scala 2
handles type parameter unpickling so we could emulate it given that this
is not the first time we run into trouble here (cf #12120), but for now
we fix the problem with the following heuristic: once we've loaded all
the type parameters of a class (which we do eagerly via
ClassUnpickler#init()), we simply stop from being entered any
subsequent type parameter we see for this class. Time will tell if this
is good enough.

While I was touching that code, I also made
ClassCompleter#completerTypeParams idempotent as one would expect it to
be.

Fixes #12641.

@smarter smarter requested a review from odersky May 31, 2021 16:49
When a type parameter of a class external to the current pickle is
referenced, Scala 2 will sometimes pickle it as if it was a type
parameter of the current class. When we unpickle such a type parameter
on our side, we enter it in the class, this leads the compiler to
believe the class has more type parameters than it actually has. This
doesn't happen in Scala 2 itself because it never enters unpickled type
parameters in the class that owns them (it must be recreating them in
some way, but I don't know how).

It would be interesting to dig deeper to understand exactly how Scala 2
handles type parameter unpickling so we could emulate it given that this
is not the first time we run into trouble here (cf scala#12120), but for now
we fix the problem with the following heuristic: once we've loaded all
the type parameters of a class (which we do eagerly via
`ClassUnpickler#init()`), we simply stop from being entered any
subsequent type parameter we see for this class. Time will tell if this
is good enough.

While I was touching that code, I also made
ClassCompleter#completerTypeParams idempotent as one would expect it to
be.

Fixes scala#12641.
@smarter smarter force-pushed the scala2-tparam-wrong-owner branch from 302c5f9 to 7535dd9 Compare May 31, 2021 16:50
@odersky odersky merged commit b955f9a into scala:master Jun 2, 2021
@odersky odersky deleted the scala2-tparam-wrong-owner branch June 2, 2021 15:47
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.

Incorrect type error when reading Scala 2.13 library
2 participants