Skip to content

unreachable code when using abstract case class pattern #10822

Closed as not planned
@fommil

Description

@fommil

In scalaz 7.3+ we're using this pattern to encode invariant ADTs

  sealed abstract class AsyncReturn[A]

  final case class Now[A](value: A)                  extends AsyncReturn[A]
  final case class MaybeLater[A](canceler: Canceler) extends AsyncReturn[A]

  sealed abstract case class Later[A] private ()     extends AsyncReturn[A]
  object Later {
    private[this] val value: Later[Nothing] = new Later[Nothing] {}
    def apply[A](): AsyncReturn[A]          = value.asInstanceOf[AsyncReturn[A]]
  }

Also discussed in #10660

However, we're now seeing false "unreachable code" errors, e.g. in
scalaz/ioeffect#9

I can't figure out how to minimise it. This IO code is dealing with low-level JVM details so it uses try and var a lot... it could be these interactions that are confusing the compiler.

Help appreciated to minimise.

In the meantime, being able to turn off the warning would be nice.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions