From 344a5ddee7ed8d31f6dd486e2a5a240d0b4be331 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Mon, 10 Jan 2022 16:54:29 +0000 Subject: [PATCH] Workaround for https://github.com/lampepfl/dotty/issues/14240 --- .../src/main/scala/cats/effect/ExitCode.scala | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/ExitCode.scala b/core/shared/src/main/scala/cats/effect/ExitCode.scala index 7435803c88..5966d1fd54 100644 --- a/core/shared/src/main/scala/cats/effect/ExitCode.scala +++ b/core/shared/src/main/scala/cats/effect/ExitCode.scala @@ -21,7 +21,26 @@ package cats.effect * * `code` is constrained to a range from 0 to 255, inclusive. */ -sealed abstract case class ExitCode private (code: Int) +// The strange encoding of this class is due to https://github.com/lampepfl/dotty/issues/14240 +sealed class ExitCode private[effect] (val code: Int) + extends Product + with Equals + with Serializable { + def canEqual(that: Any): Boolean = that.isInstanceOf[ExitCode] + + override def equals(that: Any): Boolean = that match { + case ExitCode(code) => this.code == code + case _ => false + } + + def productArity: Int = 1 + + def productElement(n: Int): Any = if (n == 0) code else throw new NoSuchElementException + + override def hashCode = code + + override def toString = s"ExitCode($code)" +} object ExitCode { @@ -32,7 +51,9 @@ object ExitCode { * the value whose 8 least significant bits are used to construct an exit code within the * valid range. */ - def apply(i: Int): ExitCode = new ExitCode(i & 0xff) {} + def apply(i: Int): ExitCode = new ExitCode(i & 0xff) + + def unapply(ec: ExitCode): Option[Int] = Some(ec.code) val Success: ExitCode = ExitCode(0) val Error: ExitCode = ExitCode(1)