From ae1b00d6235f394520ee7b5b062bada4d25a3422 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sun, 21 Nov 2021 19:13:55 +0100 Subject: [PATCH] Check that we pickle a definition before its references ... except for pattern-bound symbols because in `case x: List[t]` we pickle `List[t]` before we pickle `t` itself. The issue with t1957.scala is fixed (after staying as a TODO for 5 years!) by the level-checking improvements in the previous commits of this PR. --- compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index a195b157cacd..8f5910c3dd56 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -89,11 +89,6 @@ class TreePickler(pickler: TastyPickler) { case Some(label) => if (label != NoAddr) writeRef(label) else pickleForwardSymRef(sym) case None => - // See pos/t1957.scala for an example where this can happen. - // I believe it's a bug in typer: the type of an implicit argument refers - // to a closure parameter outside the closure itself. TODO: track this down, so that we - // can eliminate this case. - report.log(i"pickling reference to as yet undefined $sym in ${sym.owner}", sym.srcPos) pickleForwardSymRef(sym) } @@ -206,6 +201,8 @@ class TreePickler(pickler: TastyPickler) { } else if (tpe.prefix == NoPrefix) { writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect) + if !symRefs.contains(sym) && !sym.isPatternBound && !sym.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot) then + report.error(i"pickling reference to as yet undefined $tpe with symbol ${sym}", sym.srcPos) pickleSymRef(sym) } else tpe.designator match {