Skip to content

[scala 3] Error deriving JsonReader for simple enum #387

@fileremeev-collab

Description

@fileremeev-collab

I get error when trying to derive JsonReader for an enum that has opaque type field:

import tethys.*
import tethys.derivation.auto.*
import tethys.derivation.semiauto.*

object Id:
  opaque type Id = Long
  given JsonReader[Id] = tethys.JsonReader.longReader
  object Id:
    def apply(i: Long): Id = i

enum Foo(@selector val typ: String) derives JsonReader:
  case Bar(id: Id.Id) extends Foo("foo")
-- [E007] Type Mismatch Error: -------------------------------------------------
 1 |enum Foo(@selector val typ: String) derives JsonReader:
   |                                            ^
   |                                            Found:    id
   |                                            Required: Id.Id
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from rs$line$5:1
    ----------------------------------------------------------------------------
   |
   | longer explanation available when compiling with `-explain`
1 error found

And when Option[Id.Id] is used everything is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions