Skip to content

Commit 712d53b

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 e7f6a81 commit 712d53b

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
@@ -885,7 +885,12 @@ class TreeUnpickler(reader: TastyReader,
885885
}
886886
goto(end)
887887
setSpan(start, tree)
888-
if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks`
888+
889+
// Dealias any non-accessible type alias in the type of `sym`. This can be
890+
// skipped for types (see `checkNoPrivateLeaks` for why) as well as for
891+
// param accessors since they can't refer to an inaccesible type member of
892+
// the class.
893+
if !sym.isType && !sym.is(ParamAccessor) then
889894
sym.info = ta.avoidPrivateLeaks(sym)
890895

891896
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)