SHARE
TWEET

Untitled

a guest Jun 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object Encoder {
  2.   implicit def apply[R <: Product]: Encoder[R] = macro applyImpl[R]
  3.   def applyImpl[R: c.WeakTypeTag](c: blackbox.Context): c.Expr[Encoder[R]] = {
  4.     import c.universe._
  5.     c.Expr[Encoder[R]](q"""
  6.       new ${weakTypeOf[Encoder[R]]} {
  7.         override def encode(r: ${weakTypeOf[R]}): Array[Byte] =
  8.           implicitly[_root_.Serializer[${weakTypeOf[R]}]].serialize(r)
  9.         }
  10.     """)
  11.   }
  12. }
  13.      
  14. case class Record(i: Int)
  15.  
  16. object Serializers {
  17.   implicit def recordSerializer: Serializer[Record] =
  18.     (r: Record) => Array.emptyByteArray
  19. }
  20.  
  21. import Serializers._
  22.  
  23. class Processor extends BaseProcessor[Record]
  24.      
  25. // [error] Loader.scala:10:22: could not find implicit value for parameter e: Serializer[Record]
  26. // [error] class Processor extends BaseProcessor[Record]
  27. // [error]                         ^
  28. // [error] one error found
  29.      
  30. object x {
  31.   import Serializers._ // moving the import here also makes it NOT compile
  32.   class Processor extends BaseProcessor[Record]
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top