Skip to content

Commit 40e437f

Browse files
committed
TreeUnpickler: fix cycle involving param accessor
When unpickling a template like `A` in i12834.scala, the first thing we do is to unpickle its class parameters, here that's `ref`. While unpickling `ref` we run `avoidPrivateLeaks` on it which forces its info and requires unpickling `B` which refers to `A.<init>` which leads to a crash because we haven't entered `<init>` in `A` yet. We can avoid this cycle by simply not running `avoidPrivateLeaks` on param accessors, this should be safe since a primary constructor parameter cannot refer to a type member of the class. Fixes #12834.
1 parent c45fce3 commit 40e437f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,12 @@ class TreeUnpickler(reader: TastyReader,
881881
}
882882
goto(end)
883883
setSpan(start, tree)
884-
if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks`
884+
885+
// Dealias any non-accessible type alias in the type of `sym`. This can be
886+
// skipped for types (see `checkNoPrivateLeaks` for why) as well as for
887+
// param accessors since they can't refer to an inaccesible type member of
888+
// the class.
889+
if !sym.isType && !sym.is(ParamAccessor) then
885890
sym.info = ta.avoidPrivateLeaks(sym)
886891

887892
if (ctx.settings.YreadComments.value) {

tests/pos/i12834.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class A(val ref: Option[B])
2+
class B extends A(None)

0 commit comments

Comments
 (0)