Scala Macros: Accessing members with quasiquotes

后端 未结 2 584
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 18:31

I\'m trying to implement an implicit materializer as described here: http://docs.scala-lang.org/overviews/macros/implicits.html

I decided to create a macro that converts

相关标签:
2条回答
  • 2021-02-04 18:47

    The field you get with accessed.name has a special suffix attached to it, to avoid naming conflicts.

    The special suffix is scala.reflect.api.StandardNames$TermNamesApi.LOCAL_SUFFIX_STRING, which has the value, you guessed it, a space char.

    This is quite evil, of course.

    0 讨论(0)
  • 2021-02-04 19:01

    Ah, figured it out almost immediately after sending my question.

    I changed the lines

    val fields = tpe.declarations.collect {
      case field if field.isMethod && field.asMethod.isCaseAccessor => field.asMethod.accessed
    }
    

    to

    val fields = tpe.declarations.collect {
      case field if field.isMethod && field.asMethod.isCaseAccessor => field.name
    }
    

    which solved the problem.

    0 讨论(0)
提交回复
热议问题