Skip to content

Commit bed1c4a

Browse files
authored
Merge pull request #12120 from dotty-staging/fix-11173-2
Scala2Unpickler: don't unpickle the same type parameter twice
2 parents 8086e4b + 0859084 commit bed1c4a

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,16 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
434434
var name = at(nameref, () => readName()(using ctx))
435435
val owner = readSymbolRef()
436436

437-
if (name eq nme.getClass_) && defn.hasProblematicGetClass(owner.name) then
437+
var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)
438+
439+
if (name eq nme.getClass_) && defn.hasProblematicGetClass(owner.name)
440+
// Scala 2 sometimes pickle the same type parameter symbol multiple times
441+
// (see i11173 for an example), but we should only unpickle it once.
442+
|| tag == TYPEsym && flags.is(TypeParam) && symScope(owner).lookup(name.asTypeName).exists
443+
then
438444
// skip this member
439445
return NoSymbol
440446

441-
var flags = unpickleScalaFlags(readLongNat(), name.isTypeName)
442-
443447
name = name.adjustIfModuleClass(flags)
444448
if (flags.is(Method))
445449
name =
@@ -1333,4 +1337,4 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
13331337
case other =>
13341338
errorBadSignature("expected an TypeDef (" + other + ")")
13351339
}
1336-
}
1340+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import i11173.Bar
2+
3+
def test(x: Bar[_]): Unit = ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
val scala3Version = sys.props("plugin.scalaVersion")
2+
val scala2Version = "2.13.5"
3+
4+
lazy val lib = project.in(file("lib"))
5+
.settings(
6+
scalaVersion := scala2Version
7+
)
8+
9+
lazy val app = project.in(file("app"))
10+
.dependsOn(lib)
11+
.settings(
12+
scalaVersion := scala3Version
13+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
// Compile this with Scala 2.13
3+
package i11173
4+
5+
trait DU[A, B]
6+
trait H[F[_]]
7+
8+
trait Foo[E] {
9+
def foo: H[({type L[A] = DU[E, A]})#L]
10+
}
11+
12+
trait Bar[E] extends Foo[E] {
13+
def bar = foo // important note: return type not specified
14+
}
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+
> app/compile

0 commit comments

Comments
 (0)