Skip to content

Commit c74f710

Browse files
committed
Fix #6989: Make sure scalacLinkedClass finds companion when unpickling
scalacLinkedClass uses unforcedDecls which might miss a companion object when unpickling. I tried to make scalacLinekdClass stricter, but ran into problems. It turns out that it is finely balanced as it is. The fix is to make sure the owner is completed before calling scalacLinkedClass from an unpickler. I trued to do the same for the Scala2Unpickler but that ran again into problems. So this is quite the mine-field...
1 parent 840a122 commit c74f710

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ class TreeUnpickler(reader: TastyReader,
801801
ValDef(tpt)
802802
case TYPEDEF | TYPEPARAM =>
803803
if (sym.isClass) {
804+
sym.owner.ensureCompleted() // scalacLinkedClass uses unforcedDecls. Make sure it does not miss anything.
804805
val companion = sym.scalacLinkedClass
805806

806807
// Is the companion defined in the same Tasty file as `sym`?

tests/pos/i6989/Container_1.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package mypkg
2+
3+
object Container {
4+
class StringExtras(val s: String) extends AnyVal {
5+
def op(item: Int): Int = ???
6+
}
7+
}
8+
9+
trait Container {
10+
import Container._
11+
implicit def mkStringExtras(s: String): StringExtras = new StringExtras(s)
12+
}

tests/pos/i6989/SimpleTest_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package mypkg
2+
3+
class SimpleTest extends Container {
4+
"foo".op(5)
5+
}

0 commit comments

Comments
 (0)