Search code examples
mongodbscalashapeless

Labelled Generic containing `$eq`


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 ...


Solution

  • 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