Cannot get field Annotations
clementrey opened this issue · comments
Hello
I am trying to create field annotation but I was not to make it work so far. I try to use the small snippet of code in the documentation
import shapeless.Annotations
import shapeless._
import labelled._
object TestAnnotations {
case class First(s: String)
case class CC(i: Int, @First("a") s: String)
sealed trait Base
@First("b") case class BaseI(i: Int) extends Base
case class BaseS(s: String) extends Base
val ccFirsts = Annotations[First, CC]
val baseFirsts = Annotations[First, Base]
}
When I try to get the Out type ccFirsts.Out
I got the type "Nothing" whereas I am expecting something like _ <: HList
Compiled with scala 2.12.8, shapeless 2.3.3 and sbt 1.2.6
Do you what is wrong with my implementation of the example ?
Thnk you very much for your time
Clement
@clementrey How do you check that
When I try to get the Out type ccFirsts.Out I got the type "Nothing"
?
For me
implicitly[ccFirsts.Out =:= (None.type :: Some[First] :: HNil)]
implicitly[Annotations.Aux[First, CC, None.type :: Some[First] :: HNil]]
the[ccFirsts.Out =:= (None.type :: Some[First] :: HNil)]
the[Annotations.Aux[First, CC, None.type :: Some[First] :: HNil]]
Also in REPL I have:
scala> import shapeless.Annotations
import shapeless.Annotations
scala> import shapeless._
import shapeless._
scala> import labelled._
import labelled._
scala> case class First(s: String)
defined class First
scala> case class CC(i: Int, @First("a") s: String)
defined class CC
scala> sealed trait Base
defined trait Base
scala> @First("b") case class BaseI(i: Int) extends Base
defined class BaseI
scala> case class BaseS(s: String) extends Base
defined class BaseS
scala> val ccFirsts = Annotations[First, CC]
ccFirsts: shapeless.Annotations[First,CC]{type Out = None.type :: Some[First] :: shapeless.HNil} = shapeless.Annotations$$anon$1@6764bc8b
If you mean that IntelliJ IDEA generates (Alt+Enter) type Annotations.Aux[First, CC, Nothing]
for ccFirsts
then you not always should rely on types generated by IDE automatically.
You can check that the line
val ccFirsts: Annotations.Aux[First, CC, Nothing] = Annotations[First, CC]
doesn't compile
Error: type mismatch;
found : shapeless.Annotations[First,CC]{type Out = None.type :: Some[First] :: shapeless.HNil}
required: shapeless.Annotations.Aux[First,CC,Nothing]
(which expands to) shapeless.Annotations[First,CC]{type Out = Nothing}
val ccFirsts: Aux[First, CC, Nothing] = Annotations[First, CC]
Thank a lot,
I gave to intellij too much credits.
Sorry for the silly questions
Regards