tek / splain

better implicit errors for scala
MIT License
370 stars 29 forks source link

found/required types fails to correctly diff records #7

Closed danslapman closed 7 years ago

danslapman commented 7 years ago

Example:

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

  type Message = Record.`'title -> String, 'text -> String, 'receiver -> Int`.T

  def show(message: Message) = {
    println(message('title) + " " + message('text))
  }

  val mess1 =
    ('title ->> "Title:") ::
      ('text ->> "Sample text") ::
      ('receiver ->> 42L) :: HNil

  show(mess1)

Splain prints:

 String with KeyTag[Symbol with Tagged[String] {}, String] {}|String with KeyTag[Symbol with Tagged[String] {}, String] {} :: String with KeyTag[Symbol with Tagged[String] {}, String] {}|String with KeyTag[Symbol with Tagged[String] {}, String] {} :: Long with KeyTag[Symbol with Tagged[String] {}, Long] {}|Int with KeyTag[Symbol with Tagged[String] {}, Int] {} :: HNil

though the only diffenrence is 'receiver's type

danslapman commented 7 years ago

Also, is it possible to extract tag string? Scala REPL do it correctly: For

('title ->> "Title:") :: ('text ->> "Sample text") :: ('receiver ->> 42) :: HNil

Displayed type is

shapeless.::[String with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("title")],String],shapeless.::[String with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("text")],String],shapeless.::[Int with shapeless.labelled.KeyTag[Symbol with shapeless.tag.Tagged[String("receiver")],Int],shapeless.HNil]]] = Title: :: Sample text :: 42 :: HNil
tek commented 7 years ago

there you go. keep those issues coming :smiley_cat:

danslapman commented 7 years ago

@tek magnificent work! Thank You a lot!

tek commented 7 years ago

it's my pleasure!