Labelled Generic containing `$eq`

梦想与她 提交于 2019-12-23 17:27:10

问题


Shapeless 2.3.3 LabelledGeneric returns a curious result when run on the following case class:

scala> case class Foo(`$eq`: Int)
defined class Foo

scala> LabelledGeneric[Foo]
res0: shapeless.LabelledGeneric[Foo]{type Repr = Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("=")],Int] :: shapeless.HNil} = shapeless.LabelledGeneric$$anon$1@1ac7dbd3

Note the label returned is literally = instead of $eq.

Is this behaviour a quirk of shapeless or something else? Are there other identifier names that result in weird behaviour?

I require this for MongoDB serialization and this kind of a major headache for me ...


回答1:


As per Alexey's comment in the Q, this is a 'feature' in Shapeless, because of the way scala/java interop works. The latter is explained in Daniel Spiewak's blot post under "operators and overaloading".

The list of operators, per the blog, that this affects are:

op  Compiles To
=   $eq
>   $greater
<   $less
+   $plus
-   $minus
*   $times
/   div
!   $bang
@   $at
#   $hash
%   $percent
^   $up
&   $amp
~   $tilde
?   $qmark
|   $bar
\   $bslash
:   $colon


来源:https://stackoverflow.com/questions/51897645/labelled-generic-containing-eq

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