Skip to content

Unresolved symbols: when pickling file containing an anonymous class. #8651

Closed
@SimonCommits

Description

@SimonCommits

Hello,

In some file I defined an abstract class

abstract class Coroutine[+T] {
  def continue: Option[T] 
}

In another file of the same package I created an anonymous implementation of Coroutine. The continue implementation references a variable state defined within the anonymous class

object Macros {
  
 import scala.quoted._
 import scala.quoted.matching._ 
    

 inline def coroutine[T](inline body: Any): Coroutine[T] = ${ coroutineImpl('{body}) }

 def coroutineImpl[T: Type](expr: Expr[_ <: Any])(implicit qtx: QuoteContext): Expr[Coroutine[T]] = {
   import qtx.tasty.{_, given _}

   '{
     new Coroutine[T] { 
       var state: Int = 0 

       def continue: Option[T] = ${
         '{
           state = 1 //if this line is commented there are no compile errors anymore!!!
           None
         }
       }
       
     }
   }

 }
}

My aim was initially to create a function continue which when called would go to the next state (by increasing the state variable which is the root of the problem here) of the coroutine class and return the value yielded at the current state. I minimized the code so it does not make any semantical sense any more (the value returned is None and the state only gets updated to 1). Also with this minimized code an additional warning spawns on the compiler log.

Compiling those two files provokes an error. This error disappears whenever the reference to the state variable within the expression built in the continue method is removed.
So this reference seems to be the root of the error:
|Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ

Initially I referenced the state variable within a foldLeft that was within the splice of the continue method. This caused the same error(without the warning) whenever I referenced state within the foldLeft.

Here is the truncated error output (ignore the warning):

sbt:dotty-simple> compile
[info] Compiling 1 Scala source to /home/snif/hackerspace/semester/bugReproduction/target/scala-0.22/classes ...
[warn] -- Warning: /home/snif/hackerspace/semester/bugReproduction/src/main/scala/Macros.scala:18:34 
[warn] 18 |        def continue: Option[T] = ${
[warn]    |                                  ^
[warn]    |Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.
[warn] 19 |          '{
[warn] 20 |            state = 1
[warn] 21 |            None
[warn] 22 |          }
[warn] 23 |        }
[info] exception occurred while compiling /home/snif/hackerspace/semester/bugReproduction/src/main/scala/Macros.scala
java.lang.AssertionError: assertion failed: unresolved symbols: anonymous class coroutines.Coroutine[T] {...}(line 14) when pickling /home/snif/hackerspace/semester/bugReproduc
tion/src/main/scala/Macros.scala while compiling /home/snif/hackerspace/semester/bugReproduction/src/main/scala/Macros.scala
[error] ## Exception when compiling 2 sources to /home/snif/hackerspace/semester/bugReproduction/target/scala-0.22/classes
[error] java.lang.AssertionError: assertion failed: unresolved symbols: anonymous class coroutines.Coroutine[T] {...}(line 14) when pickling /home/snif/hackerspace/semester/bug
Reproduction/src/main/scala/Macros.scala
[error] dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
[error] dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:715)
[error] dotty.tools.dotc.core.quoted.PickledQuotes$.pickle(PickledQuotes.scala:102)
[error] dotty.tools.dotc.core.quoted.PickledQuotes$.pickleQuote(PickledQuotes.scala:34)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickleAsTasty$1(ReifyQuotes.scala:236)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.pickledQuote(ReifyQuotes.scala:248)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformQuotation(ReifyQuotes.scala:196)
[error] dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:94)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.op$1(ReifyQuotes.scala:415)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:417)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1251)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.op$1(ReifyQuotes.scala:415)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:417)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1257)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.op$1(ReifyQuotes.scala:415)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:417)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:97)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.op$1(ReifyQuotes.scala:415)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:417)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1347)
[error] scala.collection.immutable.List.mapConserve(List.scala:444)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1347)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1345)
[error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1271)
[error] dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
[error] dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
[error] dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:106)
[error] dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.op$1(ReifyQuotes.scala:415)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transform(ReifyQuotes.scala:417)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.transformWithCapturer(ReifyQuotes.scala:355)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.body$3(ReifyQuotes.scala:329)
[error] dotty.tools.dotc.transform.ReifyQuotes$QuoteReifier.$anonfun$1(ReifyQuotes.scala:339)
...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions