Skip to content

Commit 83b61b3

Browse files
committed
Survive duplicated symbols generated by 2.13
1 parent f01c14d commit 83b61b3

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object Printers {
3939
val quotePickling = noPrinter
4040
val plugins = noPrinter
4141
val refcheck = noPrinter
42+
val scala2unpickle = noPrinter
4243
val simplify = noPrinter
4344
val staging = noPrinter
4445
val subtyping = noPrinter

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import scala.collection.mutable
3030
import scala.collection.mutable.ListBuffer
3131
import scala.annotation.switch
3232
import reporting._
33+
import config.Printers.scala2unpickle
3334

3435
object Scala2Unpickler {
3536

@@ -491,8 +492,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
491492
sym.setFlag(Scala2x)
492493
if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || sym.is(Scala2Existential))) {
493494
val owner = sym.owner
494-
if (owner.isClass)
495-
owner.asClass.enter(sym, symScope(owner))
495+
if owner.isClass then
496+
val scope = symScope(owner)
497+
if !(sym.isType && scope.lookup(sym.name).exists) then
498+
owner.asClass.enter(sym, scope)
499+
else
500+
scala2unpickle.println(i"duplicate symbol ${sym.showLocated}")
501+
// Scala 2.13 seems sometimes generates duplicate type parameters with the same owner
502+
// For instance, in i11173. In this case, we cannot proceed with entering.
496503
}
497504
sym
498505
}

tests/pos/i11173/Lib.scala

Lines changed: 14 additions & 0 deletions
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+
}

tests/pos/i11173/Test.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
import i11173.Bar
3+
4+
def test(x: Bar[_]): Unit = ()
5+

0 commit comments

Comments
 (0)