Skip to content

Handle pickled forward references in pickled expressions #16855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class TreeUnpickler(reader: TastyReader,
*/
private val typeAtAddr = new mutable.HashMap[Addr, Type]

/** If this is a pickled quote, the owner of the quote, otherwise NoSymbol. */
private var rootOwner: Symbol = NoSymbol

/** The root symbol denotation which are defined by the Tasty file associated with this
* TreeUnpickler. Set by `enterTopLevel`.
*/
Expand Down Expand Up @@ -106,6 +109,7 @@ class TreeUnpickler(reader: TastyReader,

/** The unpickled trees */
def unpickle(mode: UnpickleMode)(using Context): List[Tree] = {
if mode != UnpickleMode.TopLevel then rootOwner = ctx.owner
assert(roots != null, "unpickle without previous enterTopLevel")
val rdr = new TreeReader(reader)
mode match {
Expand Down Expand Up @@ -1635,7 +1639,7 @@ class TreeUnpickler(reader: TastyReader,
pickling.println(i"no owner for $addr among $cs%, %")
throw ex
}
try search(children, NoSymbol)
try search(children, rootOwner)
catch {
case ex: TreeWithoutOwner =>
pickling.println(s"ownerTree = $ownerTree")
Expand Down
13 changes: 13 additions & 0 deletions tests/pos-macros/i16843a/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted.*

case class Foo(x: Int)

inline def foo = ${ fooImpl }

def fooImpl(using Quotes) =
val tmp = '{
1 match
case x @ (y: Int) => 0
}

'{}
1 change: 1 addition & 0 deletions tests/pos-macros/i16843a/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val x = foo
18 changes: 18 additions & 0 deletions tests/pos-macros/i16843b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.quoted.*

inline def foo: Int = ${ fooImpl }

def fooImpl(using Quotes): Expr[Int] =
'{
val b = ${
val a = '{
(1: Int) match
case x @ (y: Int) => 0
}
a
}

(1: Int) match
case x @ (y: Int) => 0
}

1 change: 1 addition & 0 deletions tests/pos-macros/i16843b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test = foo