Skip to content

Commit 0a458fc

Browse files
committed
Survive duplicated symbols generated by 2.13
1 parent f01c14d commit 0a458fc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,14 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
491491
sym.setFlag(Scala2x)
492492
if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || sym.is(Scala2Existential))) {
493493
val owner = sym.owner
494-
if (owner.isClass)
495-
owner.asClass.enter(sym, symScope(owner))
494+
if owner.isClass then
495+
val scope = symScope(owner)
496+
if !(sym.isType && scope.lookup(sym.name).exists) then
497+
owner.asClass.enter(sym, scope)
498+
else
499+
scala2unpickle.println(i"duplicate symbol ${sym.showLocated}")
500+
// Scala 2.13 seems sometimes generates duplicate type parameters with the same owner
501+
// For instance, in i11173. In this case, we cannot proceed with entering.
496502
}
497503
sym
498504
}

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+

tests/pos/i11173/s2/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+
}

0 commit comments

Comments
 (0)