Open mtomko opened 9 months ago
See also some discussion on Discord here: https://discord.com/channels/632150470000902164/632150470000902166/1192856719727001641
object Main {
def main(args: Array[String]): Unit = {
Left(()).recoverWith { _ =>
List.empty[Int].find(_ == 1) match {
case None => Left(())
case Some(_) => Right(())
}
}
}
}
implicit final def catsSyntaxEither[A, B](eab: Either[A, B]): EitherOps[A, B] = new EitherOps(eab)
final class EitherOps[A, B](private val eab: Either[A, B]) extends AnyVal {
def recoverWith[AA >: A, BB >: B](pf: PartialFunction[A, Either[AA, BB]]): Either[AA, BB] =
eab match {
case Left(a) if pf.isDefinedAt(a) => pf(a)
case _ => eab
}
}
@main def Main: Unit =
f{ x =>
{ (y: Int) => y } match
case _ => ()
}
def f(pf: PartialFunction[Unit, Unit]): Unit = ()
The nested lambda needs to be in the match scrutinee.
Left(()).recoverWith { _ =>
- List.empty[Int].find(_ == 1) match {
+ val a = List.empty[Int].find(_ == 1)
+ a match {
case None => Left(())
case Some(_) => Right(())
}
}
Compiler version
Minimized code
I have the example down to a fairly minimal case (~10 lines), but I have a dependency there (cats) so I made a github repository for it. You can check out the code at: https://github.com/mtomko/duplicate-method-name
Here is the Scala code in its entirety:
Output
Expectation
This code compiles and runs as expected on Scala 2.13.12, producing no output. On Scala 3.3.1, it compiles but throws a
java.lang.ClassFormatError: Duplicate method name
at runtime. I believe that this code should probably just compile and run. However, if there is truly an error in the source code, then the compiler should detect and report the error, rather than generating a class file that causes the JVM to throwClassFormatError
.