-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unresolved symbols: when pickling file containing an anonymous class. #8651
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
Comments
Does the error persist if you change def continue: Option[T] = {
state = 1
None
} |
Just tried, with the code above, the crash does not happen. So the issue is with the nested quote which refers to a local definition in an outer quoted block. /cc: @nicolasstucki |
@LeDevDuDimanche You may workaround the issue with the following change: abstract class Coroutine[+T] {
protected var state: Int
def continue: Option[T]
}
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._
'{
new Coroutine[T] {
def continue: Option[T] = {
val self: Coroutine[T] = this
${
'{
self.state = 1
None
}
}
}
}
}
}
} |
Minimized to import scala.quoted._
def coroutineImpl(using QuoteContext): Expr[Any] =
'{
new {
def state: Int = 0
${'state}
}
} We seem to not be identifying |
Fix scala#6140, fix scala#6772, fix scala#7030, fix scala#7892, fix scala#7997, fix scala#8651 and improve scala#8100.
Fix scala#6140, fix scala#6772, fix scala#7030, fix scala#7892, fix scala#7997, fix scala#8651 and improve scala#8100. Differences with previous implementation * Only track and check levels within quotes or splices * Track levels of all symbols not at level 0 * Split level checking into specialized variants for types and terms (healType/healTermType) * Detect inconsistent types rather than try to detect consistent ones * Check/heal term inconsistencies only on leaf nodes (TypeTree, RefTree, Ident, This)
Fix scala#6140, fix scala#6772, fix scala#7030, fix scala#7892, fix scala#7997, fix scala#8651 and improve scala#8100. Differences with previous implementation * Only track and check levels within quotes or splices * Track levels of all symbols not at level 0 * Split level checking into specialized variants for types and terms (healType/healTermType) * Detect inconsistent types rather than try to detect consistent ones * Check/heal term inconsistencies only on leaf nodes (TypeTree, RefTree, Ident, This)
Hello,
In some file I defined an abstract class
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 classMy 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):
The text was updated successfully, but these errors were encountered: