Skip to content

Commit 6bfde43

Browse files
committed
Handle pickled forward references in pickled expressions
To compute forward references it was assumed that the owner of that symbol can be found in the TASTy. This is not always the case with TASTy expressions of pickled quotes. The owner might be outside the quote, in this case the context already has the owner of the referenced symbol. These are local symbols defined at the top-level of the TASTy. Fixes #16843
1 parent 723d140 commit 6bfde43

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ class TreeUnpickler(reader: TastyReader,
265265
case Some(sym) =>
266266
sym
267267
case None =>
268-
val sym = forkAt(addr).createSymbol()(using ctx.withOwner(ownerTree.findOwner(addr)))
268+
val ownerInTree = ownerTree.findOwner(addr)
269+
val ctx1 =
270+
if ownerInTree.exists then ctx.withOwner(ownerInTree)
271+
else ctx // this is a pickled expression and the owner is located outside the expression (i.e. pickled quote)
272+
val sym = forkAt(addr).createSymbol()(using ctx1)
269273
report.log(i"forward reference to $sym")
270274
sym
271275
}
@@ -1620,7 +1624,6 @@ class TreeUnpickler(reader: TastyReader,
16201624
try cs match {
16211625
case ot :: cs1 =>
16221626
if (ot.addr.index == addr.index) {
1623-
assert(current.exists, i"no symbol at $addr")
16241627
current
16251628
}
16261629
else if (ot.addr.index < addr.index && addr.index < ot.end.index)

tests/pos-macros/i16843/Macro_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.quoted.*
2+
3+
inline def foo: Int = ${ fooImpl }
4+
5+
def fooImpl(using Quotes): Expr[Int] =
6+
'{
7+
val b = ${
8+
val a = '{
9+
(1: Int) match
10+
case x @ (y: Int) => 0
11+
}
12+
a
13+
}
14+
15+
(1: Int) match
16+
case x @ (y: Int) => 0
17+
}
18+

tests/pos-macros/i16843/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test = foo

0 commit comments

Comments
 (0)