Scala Macros: Accessing members with quasiquotes

孤者浪人 提交于 2019-12-03 00:32:16

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!