Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeejeeone opened this issue Mar 21, 2024 · 0 comments

Comments

@jeejeeone
Copy link

jeejeeone commented Mar 21, 2024

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant