scala-reflect

In scala 2 or 3, is it possible to debug implicit resolution process in runtime?

偶尔善良 提交于 2020-02-23 06:27:51
问题 In scala language, implicit resolution is often done in compile-time and sometimes throws obfuscating error information, one famous example of such error is when shapeless Generic throws error information like: error: could not find implicit value for parameter encoder: CsvEncoder[Foo] (see https://books.underscore.io/shapeless-guide/shapeless-guide.html for detail) A solution to this problem is to run implicit resolution algorithm (should be a graph query algorithm internally) in runtime,

In Scala 2.11+ reflection, how to reliably convert a TypeTag and a Manifest into each other?

喜你入骨 提交于 2020-01-30 11:01:11
问题 In this post: Is it possible to convert a TypeTag to a Manifest? It is indicated that a TypeTag can be converted into a Manifest using the following code: def toManifest[T:TypeTag]: Manifest[T] = { val t = typeTag[T] val mirror = t.mirror def toManifestRec(t: Type): Manifest[_] = { val clazz = ClassTag[T](mirror.runtimeClass(t)).runtimeClass if (t.typeArgs.length == 1) { val arg = toManifestRec(t.typeArgs.head) ManifestFactory.classType(clazz, arg) } else if (t.typeArgs.length > 1) { val args

scala.tools.reflect.ToolBoxError: reflective compilation has failed: cannot initialize the compiler due to java.lang.VerifyError

拈花ヽ惹草 提交于 2020-01-25 10:15:09
问题 I want to pass a scala file containing a case class so my application compiles this case class during run time and start using it. The main reason why I am doing this is because I want to avoid rebuilding my code every time the case class changes. So would be better to pass it as a parameter (in case you are wondered, the operations with this case class are generic so it is not required any rework in the transformations) I was using these post1, post2 and post3 as references. So far my

scala.tools.reflect.ToolBoxError: reflective compilation has failed: cannot initialize the compiler due to java.lang.VerifyError

牧云@^-^@ 提交于 2020-01-25 10:15:07
问题 I want to pass a scala file containing a case class so my application compiles this case class during run time and start using it. The main reason why I am doing this is because I want to avoid rebuilding my code every time the case class changes. So would be better to pass it as a parameter (in case you are wondered, the operations with this case class are generic so it is not required any rework in the transformations) I was using these post1, post2 and post3 as references. So far my