Skip to content

Commit 4f9d7c8

Browse files
committed
Avoid NPE when duplicating symbols
Fixes #10542
1 parent 8acc1cb commit 4f9d7c8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,10 @@ object Symbols {
835835
info = completer,
836836
privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
837837
annotations = odenot.annotations)
838-
copy.registeredCompanion =
839-
copy.registeredCompanion.subst(originals, copies)
838+
copy.denot match
839+
case cd: ClassDenotation =>
840+
cd.registeredCompanion = cd.unforcedRegisteredCompanion.subst(originals, copies)
841+
case _ =>
840842
}
841843

842844
copies.foreach(_.ensureCompleted()) // avoid memory leak

tests/pos/i10542.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package test1:
2+
3+
trait Foo {
4+
inline def foo[A](t: => A): Unit = ()
5+
}
6+
7+
object Bar extends Foo
8+
9+
object Test {
10+
Bar.foo {
11+
sealed trait T1
12+
case object S1 extends T1
13+
}
14+
}
15+
/*
16+
package test2:
17+
18+
trait Foo {
19+
inline def foo[A](t: => A): Unit = ()
20+
}
21+
22+
object Bar extends Foo
23+
24+
object Test {
25+
Bar.foo {
26+
trait T1
27+
val array = Array(new T1 {})
28+
}
29+
}*/

0 commit comments

Comments
 (0)