Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected diverging implicit with singleton type #37

Open
alexarchambault opened this issue Mar 31, 2016 · 2 comments
Open

Unexpected diverging implicit with singleton type #37

alexarchambault opened this issue Mar 31, 2016 · 2 comments
Labels

Comments

@alexarchambault
Copy link
Owner

Reported by @raulraja on the gitter of shapeless (https://gitter.im/milessabin/shapeless?at=56fcf50fbbffcc665faad6e5)

import org.scalacheck.Shapeless._
import shapeless._
import org.scalacheck._

def test[L <: HList : Arbitrary](l : L) : Arbitrary[L] = implicitly[Arbitrary[L]]

test(1 :: HNil) // works

import shapeless.syntax.singleton._

test(1.narrow :: HNil)

Surprisingly, explicitly specifying the type parameter of test makes this work again,

test[Witness.`1`.T :: HNil](1.narrow :: HNil) // fine
@alexarchambault
Copy link
Owner Author

@milessabin Does this ring a bell to you? This looks quite similar to #7 (comment), although removing arbContainer2 from scalacheck-shapeless doesn't address the issue here (one just gets "cannot find implicit value..." then).

Unlike #7, the problem only appears when singleton types are involved.

@milessabin
Copy link

No, I've not seen this before. It might be my fault, but I'm tempted to call this a compiler bug. Here's something else which works,

scala> type One = Witness.`1`.T
defined type alias One

scala> test((1: One) :: HNil)
res7: org.scalacheck.Arbitrary[shapeless.::[One,shapeless.HNil]] = org.scalacheck.ArbitraryLowPriority$$anon$1@595812b9

Also note,

scala> 1.narrow
res8: Int(1) = 1

scala> (1.narrow: One)
res9: One = 1

And again,

scala> def typed[T](t: T)(implicit ev: T =:= (One :: HNil)) = {}
typed: [T](t: T)(implicit ev: =:=[T,shapeless.::[One,shapeless.HNil]])Unit

scala> typed(1 :: HNil)
<console>:26: error: Cannot prove that shapeless.::[Int,shapeless.HNil] =:= shapeless.::[One,shapeless.HNil].
       typed(1 :: HNil)
            ^

scala> typed(1.narrow :: HNil)

scala>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants