Skip to content

Scala 3: derivation for sealed traits with case objects #281

Closed
susliko opened this issue Apr 23, 2023 · 1 comment
Closed

Scala 3: derivation for sealed traits with case objects #281

susliko opened this issue Apr 23, 2023 · 1 comment
Milestone

Comments

@susliko
Copy link
Contributor

susliko commented Apr 23, 2023

Problem

An attempt to derive ElementEncoder for sealed trait with case object implementations results in compilation error in Scala 3, while compiles in Scala 2

 sealed trait Foo derives ElementEncoder
   object Foo:
     case object A extends Foo derives ElementEncoder
     case object B extends Foo derives ElementEncoder
[error] 60 |      sealed trait Foo derives ElementEncoder
[error]    |                               ^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.AssertionError: assertion failed
[error]    |    at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1093)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1092)
[error]    |    at ru.tinkoff.phobos.derivation.common$.extractSumTypeChildren$$anonfun$1(common.scala:79)
[error]    |    at scala.collection.immutable.List.map(List.scala:246)
[error]    |    at ru.tinkoff.phobos.derivation.common$.extractSumTypeChildren(common.scala:79)
[error]    |    at ru.tinkoff.phobos.derivation.encoder$.deriveSum$$anonfun$1(encoder.scala:180)
[error]    |    at ru.tinkoff.phobos.derivation.encoder$.deriveSum$$anonfun$adapted$1(encoder.scala:195)
[error]    |    ... dotc frames
[error]    |    at ru.tinkoff.phobos.derivation.encoder$.deriveSum(encoder.scala:195)
[error]    |    at ru.tinkoff.phobos.derivation.encoder$.deriveElementEncoderImpl(encoder.scala:37)
[error]    |
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from encoder.scala:19
[error] 19 |    ${deriveElementEncoderImpl('{config})}
[error]    |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from encoder.scala:19
[error]  8 |    encoder.deriveElementEncoder[T](ElementCodecConfig.default)
[error]    |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expected behavior

ElementEncoder is derived and works as follows

implicit val encoder: XmlEncoder[Foo] = XmlEncoder.fromElementEncoder("foo")
assert(XmlEncoder[Foo].encode(Foo.A) == Right(
  """<?xml version='1.0' encoding='UTF-8'?>
        <foo xmlns:ans1="http://www.w3.org/2001/XMLSchema-instance" ans1:type="A"/>
 """))
@valentiay
Copy link
Contributor

Closed by #283

@valentiay valentiay added this to the v0.21.0 milestone May 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants