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

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

Closed
scabug opened this issue Feb 17, 2017 · 1 comment
Closed

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

scabug opened this issue Feb 17, 2017 · 1 comment

Comments

@scabug
Copy link

scabug commented Feb 17, 2017

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.

@scabug
Copy link
Author

scabug commented Feb 17, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10197?orig=1
Reporter: Tomas Mikula (tomas.mikula-at-gmail.com)
Affected Versions: 2.12.1

TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 12, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 14, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 26, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under a compiler flag
-Yhk-typevar-unification.

Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 27, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
TomasMikula added a commit to TomasMikula/scala that referenced this issue Sep 28, 2017
Can cause ambiguous implicits, so is under the compiler flag
-Xsource:2.13

Fixes scala/bug#10185
Fixes scala/bug#10195
Fixes scala/bug#10197
Fixes scala/bug#10213
Fixes scala/bug#10238
Fixes scala/bug#10372
Presents an alternative fix to scala/bug#6895.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant