anorm icon indicating copy to clipboard operation
anorm copied to clipboard

Unreachable case except for null warning by Macro.namedParser with Scala 3 enum

Open jeejeeone opened this issue 1 year ago • 0 comments

Anorm Version (2.5.x / etc)

2.7.1-f0a340eb-SNAPSHOT with Scala 3.3.1

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

MacOS 13.5.1

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "15.0.1" 2020-10-20 OpenJDK Runtime Environment (build 15.0.1+9-18) OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)

Expected Behavior

Reproducer compiles without warnings

Actual Behavior

Compiles with warning

[warn] ./reproducer.sc:23:17
[warn] Unreachable case except for null (if this is intentional, consider writing case null => instead).
[warn] val rowParser = anorm.Macro.namedParser[AnormRow]
[warn]                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Reproducible Test Case

Reproducer repo https://github.com/jeejeeone/anorm-reproducer/tree/main (after first sbt compile warning goes away)

Reproduce with scala-cli:

//> using scala 3.3.1
//> using repository sonatype:snapshots
//> using lib "org.playframework.anorm::anorm::2.7.1-f0a340eb-SNAPSHOT"
import anorm.Column.nonNull
import anorm.{Column, MetaDataItem, TypeDoesNotMatch}

enum SomeEnum(val name: String) {
  case EnumItem extends SomeEnum("enum item")
}

case class AnormRow(enumItem: SomeEnum)

given Column[SomeEnum] =
  nonNull[SomeEnum] { (value, meta) =>
    val MetaDataItem(qualified, _, _) = meta

    value match {
      case string: String if string == "enum item"      => Right(SomeEnum.EnumItem)
      case _ => Left(TypeDoesNotMatch(s"Cannot convert $value"))
    }
  }

val rowParser = anorm.Macro.namedParser[AnormRow]

jeejeeone avatar Mar 21 '24 07:03 jeejeeone