bug icon indicating copy to clipboard operation
bug copied to clipboard

Nothing is kind-polymorphic, but its aliases are not

Open scabug opened this issue 9 years ago • 3 comments

Add this to the list of why it's so hard to use an alternative Predef.

package p

object Bug {
  def empty[F[_]] = null

  type LocalNothing = scala.Nothing

  def f = empty[Nothing]
  def g = empty[LocalNothing]
  // a.scala:11: error: kinds of the type arguments (p.Bug.LocalNothing) do not conform to the expected kinds of the type parameters (type F).
  // p.Bug.LocalNothing's type parameters do not match type F's expected parameters:
  // type LocalNothing has no type parameters, but type F has one
  //   def g = empty[LocalNothing]
  //                ^
  // one error found
}

scabug avatar Oct 07 '16 00:10 scabug

Imported From: https://issues.scala-lang.org/browse/SI-9951?orig=1 Reporter: @paulp

scabug avatar Oct 07 '16 00:10 scabug

@paulp said (edited on Oct 7, 2016 12:31:41 AM UTC): The way I discovered this is pretty nutball. There was a call to scalaz.stream.Process.empty which stopped compiling after I stopped importing the $conforms implicit, which is simply reflexive. As paul chiusano discusses here, it needs to infer F and O in def empty[F[_], O]. Maybe you can see where this is going.

It won't allow quasar.Predef.Nothing to be inferred for F because it thinks it has the wrong kind. But if we have a nice A => A implicit in scope, it will "translate" from a type alias to the dealiased type, utilizing the identity function.

scabug avatar Oct 07 '16 00:10 scabug

I suspect this is out of scope for Scala 2, but I'm not actually sure

SethTisue avatar Oct 11 '24 02:10 SethTisue