-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CyclicReference exception when working with toExprOfList
in context of Reflection
#6765
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
Worth noting that {
type x$1$_$1
val x$2: x$1$_$1 = "One"
{
type x$1$_$1
val x$2: x$1$_$1 = "Two"
scala.Nil.::[x$1$_$1](x$2)
}.::[x$1$_$1](x$2)
} Which is not a Scala code that would typecheck. If you try to execute it as is: [error] -- [E007] Type Mismatch Error: /Users/anatolii/Projects/dotty/playground/core/src/main/scala/playground/Main.scala:42:27
[error] 42 | val x$2: x$1$_$1 = "Two"
[error] | ^^^^^
[error] | Found: String("Two")
[error] | Required: x$1$_$1
[error] -- [E007] Type Mismatch Error: /Users/anatolii/Projects/dotty/playground/core/src/main/scala/playground/Main.scala:43:29
[error] 43 | scala.Nil.::[x$1$_$1](x$2)
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | Found: List[x$1$_$1]
[error] | Required: Int As to def (list: List[Expr[T]]) toExprOfList[T] given Type[T]: Expr[List[T]] = list match {
case x :: xs => '{ $x :: ${xs.toExprOfList} }
case Nil => '{ Nil }
} I believe def flattenExpr[T](exs: List[Expr[T]]) given (tt: Type[T]): Expr[List[T]] =
exs.foldRight('{Nil: List[$tt]}) { (next, accum) => '{$next :: $accum} } Bug-wise, it behaves the same way as def flattenExprStr(exs: List[Expr[String]]): Expr[List[String]] =
exs.foldRight('{Nil: List[String]}) { (next, accum) => '{$next :: $accum} } And call it as: inline def crash = ${crashImpl}
def crashImpl given (refl: Reflection) = {
import refl._
// val res = List('{"One"}).toExprOfList
val res = flattenExprStr(List('{"One"}))
println(res.show)
res
} All works well. This one also works: def flattenExprStr2(exs: List[Expr[String]]): Expr[List[String]] = {
val tpe = the[Type[String]]
exs.foldRight('{Nil: List[${tpe}]}) { (next, accum) => '{$next :: $accum} }
} However, this one: def flattenExprStr3(exs: List[Expr[String]]): Expr[List[String]] =
exs.foldRight('{Nil: List[${the[Type[String]]}]}) { (next, accum) => '{$next :: $accum} } Says: [error] -- Error: /Users/anatolii/Projects/dotty/playground/macros/src/main/scala/playground/macros.scala:49:32
[error] 49 | exs.foldRight('{Nil: List[${the[Type[String]]}]}) { (next, accum) => '{$next :: $accum} }
[error] | ^^^^^^^^^^^^^^^^^
[error] | quoted.Type[String] is not stable |
This was fixed in #6700 |
Fix #6765: Add regression test
Uh oh!
There was an error while loading. Please reload this page.
minimized code
Macro:
Usage:
If as much as one of the four pointed out comments is applied, the code works.
Stack trace
The text was updated successfully, but these errors were encountered: