Skip to content

Commit c70f6e5

Browse files
committedMay 10, 2019
Fix #6484: Properly unpickle some Scala 2 type lambdas
Scala 2 pickles both type lambdas and polymorphic methods using the POLYtpe tag. When we unpickle them, we distinguish them based on whether the symbol for the owner of the type parameters is a term or a type, but it seems that some type parameter symbols for type lambdas are pickled with a term owner. In Eff for example, the pickled information for the `runReader` method in: https://github.com/atnos-org/eff/blob/85bd7b2dc1cd26c22e45d69910755f2a9ea4ece4/shared/src/main/scala/org/atnos/eff/syntax/reader.scala#L12 contains a POLYtpe `[A] => A` (because `Reader` is defined in cats as `type Reader[A, B] = Kleisli[Id, A, B]`, and `Id` is defined as `type Id[A] = A`), somehow the owner of the symbol for `A` is the object `reader` defined in the same file. That doesn't make any sense to me, but just checking if the owner is actually a method should work just as well and fixes the problem. Given that Scala 2 unpickling support is a temporary crutch I think that's good enough.
1 parent cdd844f commit c70f6e5

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed
 

‎compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ object Scala2Unpickler {
4646
/** Convert temp poly type to poly type and leave other types alone. */
4747
def translateTempPoly(tp: Type)(implicit ctx: Context): Type = tp match {
4848
case TempPolyType(tparams, restpe) =>
49-
(if (tparams.head.owner.isTerm) PolyType else HKTypeLambda)
49+
// This check used to read `owner.isTerm` but that wasn't always correct,
50+
// I'm not sure `owner.is(Method)` is 100% correct either but it seems to
51+
// work better. See the commit message where this change was introduced
52+
// for more information.
53+
(if (tparams.head.owner.is(Method)) PolyType else HKTypeLambda)
5054
.fromParams(tparams, restpe)
5155
case tp => tp
5256
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scalaVersion := sys.props("plugin.scalaVersion")
2+
3+
libraryDependencies +=
4+
("org.atnos" %% "eff" % "5.4.1").withDottyCompat(scalaVersion.value)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import cats._
2+
import cats.data._
3+
import cats.implicits._
4+
import org.atnos.eff._
5+
import org.atnos.eff.all._
6+
import org.atnos.eff.syntax.all._
7+
8+
import scala.language.implicitConversions
9+
10+
object Test {
11+
def resolve[T](e: Eff[Fx1[[X] => Kleisli[Id, String, X]], T], g: String): T =
12+
e.runReader[String](g)(Member.Member1[[X] => Kleisli[Id, String, X]]).run
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> compile

0 commit comments

Comments
 (0)
Please sign in to comment.