Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Writing Scala 3 enums is broken

See original GitHub issue

Issue Description

Trying to write Scala 3 enum values actually writes always the first one.

Test reproducing the problem

package upickle

import scala.language.implicitConversions
import utest._

import upickle.default._

object EnumTests extends TestSuite {

  enum SimpleEnum {
    case A, B

  val tests = Tests {
    test("simple") {
      given ReadWriter[SimpleEnum] = macroRW[SimpleEnum]
      test("enum write") {
        val parsed = write(SimpleEnum.B)
        val expected = """{"$type":"upickle.EnumTests.SimpleEnum.B"}"""
        assert(parsed == expected)

Fails with:

X upickle.EnumTests.simple.enum write 71ms 
  utest.AssertionError: parsed == expected
  parsed: String = {"$type":"upickle.EnumTests.SimpleEnum.A"}
  expected: String = {"$type":"upickle.EnumTests.SimpleEnum.B"}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

htmldougcommented, Oct 1, 2021

There might be something useful that can be ported over from

JD557commented, Jul 24, 2022

Looks like ADTs encoded using enums also fail.

Using the Color example in

import upickle.default._

enum Color(val rgb: Int):
  case Red   extends Color(0xFF0000)
  case Green extends Color(0x00FF00)
  case Blue  extends Color(0x0000FF)
  case Mix(mix: Int) extends Color(mix)

object Color {
  implicit val rw: ReadWriter[Color] = macroRW

Fails with

Exception occurred while executing macro expansion.
java.lang.Exception: Enumeration valueOf method not found
	at upickle.implicits.macros.macros$package$.$anonfun$8(macros.scala:104)
	at scala.Option.getOrElse(Option.scala:201)
	at upickle.implicits.macros.macros$package$.enumValueOfImpl(macros.scala:105)
Read more comments on GitHub >

github_iconTop Results From Across the Web

An example of using enums in Scala 3 (Dotty) - Alvin Alexander
Here's a quick example of how to use Scala 3 enums, including using them as constructor and method parameters, and in a match...
Read more >
An enumeration is used to define a type consisting of a set of named values. ... This defines a new sealed class, Color...
Read more >
(De)serialize enum as string in Scala 3 - Stack Overflow
I am trying to find a simple and efficient way to (de)serialize enums in Scala 3 using circe . Consider the following example:...
Read more >
Learn How Enum Function Work in Scala? - eduCBA
3 ) Scala enum hierarchy;. Serializable; Enumeration; RoundingMode. Below is one example which will explain its working; what we are doing here is...
Read more >
Enums in Scala 3 - Rock the JVM Blog
This article is for Scala programmers of all levels, and particularly for those Scala programmers who have been emulating enums in Scala 2...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found