Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-10197

Implicit resolution with type aliases with phantom types doesn't work

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: Scala 2.12.1
    • Fix Version/s: None
    • Component/s: Compiler (Misc)
    • Labels:
      None

      Description

      import scala.language.higherKinds
       
      final case class Getter[S, A](get: S => A)
       
      final case class Wrap[F[_], A](value: F[A])
       
      object Wrap {
        // Helper to defer specifying second argument to Wrap.
        //  Basically a type lambda specialized for Wrap.
        // Wr[F]#ap[A] =:= Wrap[F, A]
        type Wr[F[_]] = { type ap[A] = Wrap[F, A] }
       
        implicit def unwrapper[F[_], A]: Getter[Wrap[F, A], F[A]] =
          Getter(w => w.value)
      }
       
      object Test {
        import Wrap._
       
        type Foo[A] = List[A]
        type Bar[A] = String
       
        type WrapFoo1[A] = Wrap[Foo, A]
        type WrapBar1[A] = Wrap[Bar, A]
       
        implicitly[Getter[WrapFoo1[Int], Foo[Int]]] // OK
        implicitly[Getter[WrapBar1[Int], Bar[Int]]] // OK
       
        type WrapFoo2[A] = Wr[Foo]#ap[A]
        type WrapBar2[A] = Wr[Bar]#ap[A]
       
        // here's evidence that the new types are the same as the old ones
        implicitly[WrapFoo2[Int] =:= WrapFoo1[Int]]
        implicitly[WrapBar2[Int] =:= WrapBar1[Int]]
       
        // but implicit resolution doesn't work as before
        implicitly[Getter[WrapFoo2[Int], Foo[Int]]] // OK
        implicitly[Getter[WrapBar2[Int], Bar[Int]]] // error: could not find implicit value for parameter
                                                    //   e: Getter[Test.WrapBar2[Int],Test.Bar[Int]]
      }
      

      Note that it is the combination of type alias with phantom type parameter (type Bar[A] = String) and type lambda (Wr[Bar]#ap) that is problematic. Each of the three simpler cases works.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              tomas.mikula@gmail.com Tomas Mikula
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: