I have been looking into the details of shapeless singletons and have encountered a small example that doesn't work as expected. I thought that as long as we pass a singleton type to a method, there should be an implicit Witness.Aux[_] available in scope:
import shapeless._
import syntax.singleton._
object SingletonTest extends App {
def check[K](a: K)(implicit witness: Witness.Aux[K]): Unit = {
println(witness.value)
}
val b = 'key.narrow
val c: Witness.`'key`.T = b
check(c) // Works!
check(b) /* Fails: shapeless.this.Witness.apply is not a valid implicit value for shapeless.Witness.Aux[Symbol with shapeless.tag.Tagged[String("key")]] because:
hasMatchingSymbol reported error: Type argument Symbol with shapeless.tag.Tagged[String("key")] is not a singleton type */
}
I would expect the types of b and c in the example to be the same (and checking it with =:= succeeds). If I add an implicit Witness[Witness.'key
.T] into scope manually, the code compiles.
Environment: Scala 2.11.8; Shapeless 2.3.0