Skip to content

Commit eb92c52

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 eb92c52

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,9 @@ class TreeUnpickler(reader: TastyReader,
16201620
try cs match {
16211621
case ot :: cs1 =>
16221622
if (ot.addr.index == addr.index) {
1623-
assert(current.exists, i"no symbol at $addr")
1624-
current
1623+
// If current does not exist it is beacause this is a pickled expression
1624+
// and the owner is located outside the expression (i.e. pickled quote).
1625+
current.orElse(ctx.owner)
16251626
}
16261627
else if (ot.addr.index < addr.index && addr.index < ot.end.index)
16271628
search(ot.children, reader.symbolAt(ot.addr))

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)