diff --git a/compiler/src/dotty/tools/dotc/config/Printers.scala b/compiler/src/dotty/tools/dotc/config/Printers.scala index 27391154591f..9ee4ee0815aa 100644 --- a/compiler/src/dotty/tools/dotc/config/Printers.scala +++ b/compiler/src/dotty/tools/dotc/config/Printers.scala @@ -39,6 +39,7 @@ object Printers { val quotePickling = noPrinter val plugins = noPrinter val refcheck = noPrinter + val scala2unpickle = noPrinter val simplify = noPrinter val staging = noPrinter val subtyping = noPrinter diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 54a7ad91e434..a769bf6af08f 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -30,6 +30,7 @@ import scala.collection.mutable import scala.collection.mutable.ListBuffer import scala.annotation.switch import reporting._ +import config.Printers.scala2unpickle object Scala2Unpickler { @@ -491,8 +492,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas sym.setFlag(Scala2x) if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || sym.is(Scala2Existential))) { val owner = sym.owner - if (owner.isClass) - owner.asClass.enter(sym, symScope(owner)) + if owner.isClass then + val scope = symScope(owner) + if !(sym.isType && scope.lookup(sym.name).exists) then + owner.asClass.enter(sym, scope) + else + scala2unpickle.println(i"duplicate symbol ${sym.showLocated}") + // Scala 2.13 seems sometimes generates duplicate type parameters with the same owner + // For instance, in i11173. In this case, we cannot proceed with entering. } sym } diff --git a/tests/pos/i11173/Lib.scala b/tests/pos/i11173/Lib.scala new file mode 100644 index 000000000000..468d4767957c --- /dev/null +++ b/tests/pos/i11173/Lib.scala @@ -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 +} diff --git a/tests/pos/i11173/Test.scala b/tests/pos/i11173/Test.scala new file mode 100644 index 000000000000..e65031520396 --- /dev/null +++ b/tests/pos/i11173/Test.scala @@ -0,0 +1,5 @@ + +import i11173.Bar + +def test(x: Bar[_]): Unit = () +