scala-nameof icon indicating copy to clipboard operation
scala-nameof copied to clipboard

Compile time whitebox macro returns a type that is too wide

Open tribbloid opened this issue 4 years ago • 0 comments

Demo:

  import shapeless.syntax.singleton._
  import shapeless.record._

  it("can get name singleton") {

    val t1 = NameOf.nameOfType[Seq[Int]]

    val record = (t1 ->> "r") :: "a" ->> 5 :: HNil

    val r = record.apply("Seq")

    println(r)
  }

which compiles to the following error:

[Error] /home/peng/git/shapesafe/core/src/test/scala/org/shapesafe/core/debugging/InfoCTSpec.scala:19: No field String("Seq") in record String with shapeless.labelled.KeyTag[t1.type,String] :: Int with shapeless.labelled.KeyTag[String("a"),Int] :: shapeless.HNil
one error found

This doesn't use the full potential of the macro, as t1 can be assigned a singleton type "Seq" in scala 2.13, or a witnessed type in scala < 2.13 using shapeless

The following works however in scala 2.13, not sure how:

  import shapeless.syntax.singleton._
  import shapeless.record._

  it("can get name singleton") {

    val t1: "Seq" = NameOf.nameOfType[Seq[Int]]

    val record = (t1 ->> "r") :: "a" ->> 5 :: HNil

    val r = record.apply("Seq")

    println(r)
  }

tribbloid avatar Apr 28 '21 02:04 tribbloid