each icon indicating copy to clipboard operation
each copied to clipboard

Error "Macro has not been expanded" when using monadic Nothing

Open dominique-unruh opened this issue 9 years ago • 1 comments

In monadic[F] { ... }, if each is applied to a monad of type F[Nothing], a compilation error "Macro has not been expanded" occurs.

F[Nothing] is a natural type for a fail operation (e.g., Nil, None) in a monad, since the return value can be upcast to anything (e.g., val x = if (x >= 0) sqrt(x) else None.each would be a use case).

Example code:

object MonadicNeedsCast {
  def main(args: Array[String]): Unit = {
    val monad = monadic[Option] {
      None.each // Normally, this would be inside an if and represent a failure of the computation
//      (None:Option[Unit]).each // This one works
      55
    }
    println(monad) // Should be None
  }
}

The error also appears with monadic[List] or with custom monads. It also appears when using fail.each where fail has type [T]fail( => T).

I am using Scala 2.11.8 and Each 2.0.0.

dominique-unruh avatar Aug 13 '16 11:08 dominique-unruh

Seems like a bug in Scala compiler: https://issues.scala-lang.org/browse/SI-9889

Atry avatar Aug 13 '16 12:08 Atry