Skip to content

Commit

Permalink
Scala2Unpickler: don't unpickle the same type parameter twice
Browse files Browse the repository at this point in the history
Fixes #11173.
Fixes #11984.
  • Loading branch information
smarter committed Apr 17, 2021
1 parent 45b8dc0 commit f40070a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,16 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
var name = at(nameref, () => readName()(using ctx))
val owner = readSymbolRef()

if (name eq nme.getClass_) && defn.hasProblematicGetClass(owner.name) then
var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)

if (name eq nme.getClass_) && defn.hasProblematicGetClass(owner.name)
// Scala 2 sometimes pickle the same type parameter symbol multiple times
// (see i11173 for an example), but we should only unpickle it once.
|| tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists
then
// skip this member
return NoSymbol

var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)

name = name.adjustIfModuleClass(flags)
if (flags.is(Method))
name =
Expand Down Expand Up @@ -1333,4 +1337,4 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
case other =>
errorBadSignature("expected an TypeDef (" + other + ")")
}
}
}
3 changes: 3 additions & 0 deletions sbt-dotty/sbt-test/scala2-compat/i11173/app/App.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import i11173.Bar

def test(x: Bar[_]): Unit = ()
13 changes: 13 additions & 0 deletions sbt-dotty/sbt-test/scala2-compat/i11173/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
val scala3Version = sys.props("plugin.scalaVersion")
val scala2Version = "2.13.5"

lazy val lib = project.in(file("lib"))
.settings(
scalaVersion := scala2Version
)

lazy val app = project.in(file("app"))
.dependsOn(lib)
.settings(
scalaVersion := scala3Version
)
14 changes: 14 additions & 0 deletions sbt-dotty/sbt-test/scala2-compat/i11173/lib/Lib.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

// Compile this with Scala 2.13
package i11173

trait DU[A, B]
trait H[F[_]]

trait Foo[E] {
def foo: H[({type L[A] = DU[E, A]})#L]
}

trait Bar[E] extends Foo[E] {
def bar = foo // important note: return type not specified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
1 change: 1 addition & 0 deletions sbt-dotty/sbt-test/scala2-compat/i11173/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> app/compile

0 comments on commit f40070a

Please sign in to comment.