Skip to content

Commit

Permalink
TreeUnpickler: fix cycle involving param accessor
Browse files Browse the repository at this point in the history
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 scala#12834.
  • Loading branch information
smarter committed Jun 18, 2021
1 parent c45fce3 commit 40e437f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions tests/pos/i12834.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class A(val ref: Option[B])
class B extends A(None)

0 comments on commit 40e437f

Please sign in to comment.