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

Type of Nothing is lost when multiple implicits are summoned for it in a chain #11715

Open
neko-kai opened this issue Aug 28, 2019 · 1 comment

Comments

@neko-kai
Copy link

commented Aug 28, 2019

Example:

import scala.reflect.runtime.universe.{TypeTag, typeTag}

final class Tag[T](t: TypeTag[T])
object Tag {
  implicit def ev[T: TypeTag]: Tag[T] = new Tag(typeTag)
}

final class X[T](t: Tag[T])
object X {
  def apply[T: X]: X[T] = implicitly

  implicit def ev[T](implicit t: Tag[T]): X[T] = new X(t)

  // this is ok
//  implicit def ev[T](implicit t: TypeTag[T]): X[T] = new X(new Tag(t))
}

object App extends App {
  // ok
  X[Int]
  X[Singleton]
  X[Any]
  // could not find implicit value for evidence parameter of type X[Nothing]
  X[Nothing]
}

Nothing morphed into T >: Nothing in the second chained implicit. Tested on 2.13.0, 2.12.9.
-Xlog-implicits output:

[info] example.scala:20:4: materializing requested reflect.runtime.universe.type.TypeTag[Int] using scala.reflect.api.`package`.materializeTypeTag[Int](scala.reflect.runtime.`package`.universe)
[info]   X[Int]
[info]    ^
[info] example.scala:21:4: materializing requested reflect.runtime.universe.type.TypeTag[Singleton] using scala.reflect.api.`package`.materializeTypeTag[Singleton](scala.reflect.runtime.`package`.universe)
[info]   X[Singleton]
[info]    ^
[info] example.scala:22:4: materializing requested reflect.runtime.universe.type.TypeTag[Any] using scala.reflect.api.`package`.materializeTypeTag[Any](scala.reflect.runtime.`package`.universe)
[info]   X[Any]
[info]    ^
[info] example.scala:24:4: materializing requested reflect.runtime.universe.type.TypeTag[T] using scala.reflect.api.`package`.materializeTypeTag[T](scala.reflect.runtime.`package`.universe)
[info]   X[Nothing]
[info]    ^
[info] example.scala:24:4: X.ev is not a valid implicit value for X[Nothing] because:
[info] hasMatchingSymbol reported error: type mismatch;
[info]  found   : Tag[Nothing]
[info]  required: Tag[T]
[info] Note: Nothing <: T, but class Tag is invariant in type T.
[info] You may wish to define T as +T instead. (SLS 4.5)
[info]   X[Nothing]
[info]    ^
[error] example.scala:24:4: could not find implicit value for evidence parameter of type X[Nothing]
[error]   X[Nothing]
[error]    ^

Currently working around that in multiple places by replacing implicit chains with macros.

@Jasper-M

This comment has been minimized.

Copy link
Member

commented Aug 28, 2019

Probably an incarnation of the ancient #4982.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.