Skip to content

Commit c3071b2

Browse files
committed
Fix opaque companion selftype pickling
1 parent 9e02a61 commit c3071b2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,11 @@ class Typer extends Namer
15781578
val constr1 = typed(constr).asInstanceOf[DefDef]
15791579
val parentsWithClass = ensureFirstTreeIsClass(parents mapconserve typedParent, cdef.namePos)
15801580
val parents1 = ensureConstrCall(cls, parentsWithClass)(superCtx)
1581-
val self1 = typed(self)(ctx.outer).asInstanceOf[ValDef] // outer context where class members are not visible
1581+
var self1 = typed(self)(ctx.outer).asInstanceOf[ValDef] // outer context where class members are not visible
1582+
if (cls.isOpaqueCompanion) {
1583+
// this is necessary to ensure selftype is correctly pickled
1584+
self1 = tpd.cpy.ValDef(self1)(tpt = TypeTree(cls.classInfo.selfType))
1585+
}
15821586
if (self1.tpt.tpe.isError || classExistsOnSelf(cls.unforcedDecls, self1)) {
15831587
// fail fast to avoid typing the body with an error type
15841588
cdef.withType(UnspecifiedErrorType)

0 commit comments

Comments
 (0)