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

Backport: Scala2Unpickler: don't unpickle the same type parameter twice #12129

Merged
merged 1 commit into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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