From 40e437f3c85de7dae0b31f6c0f10708535ef7bd7 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 16 Jun 2021 00:31:44 +0200 Subject: [PATCH] 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.` which leads to a crash because we haven't entered `` 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. --- .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 7 ++++++- tests/pos/i12834.scala | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i12834.scala diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 10d4e780b6f9..977b3f714d53 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -881,7 +881,12 @@ class TreeUnpickler(reader: TastyReader, } goto(end) setSpan(start, tree) - if (!sym.isType) // Only terms might have leaky aliases, see the documentation of `checkNoPrivateLeaks` + + // Dealias any non-accessible type alias in the type of `sym`. This can be + // skipped for types (see `checkNoPrivateLeaks` for why) as well as for + // param accessors since they can't refer to an inaccesible type member of + // the class. + if !sym.isType && !sym.is(ParamAccessor) then sym.info = ta.avoidPrivateLeaks(sym) if (ctx.settings.YreadComments.value) { diff --git a/tests/pos/i12834.scala b/tests/pos/i12834.scala new file mode 100644 index 000000000000..c007eaf6844f --- /dev/null +++ b/tests/pos/i12834.scala @@ -0,0 +1,2 @@ +class A(val ref: Option[B]) +class B extends A(None)