Skip to content

Can't derive Schema for a case class with 23+ fields and an overloaded apply method #859

@ghostdogpr

Description

@ghostdogpr

Reproducer: https://scastie.scala-lang.org/kw7lsgdOQtyGMrEz3gaUMA

import zio.schema.*

case class A(
    s1: String,
    s2: String,
    s3: String,
    s4: String,
    s5: String,
    s6: String,
    s7: String,
    s8: String,
    s9: String,
    s10: String,
    s11: String,
    s12: String,
    s13: String,
    s14: String,
    s15: String,
    s16: String,
    s17: String,
    s18: String,
    s19: String,
    s20: String,
    s21: String,
    s22: String,
    s23: String
) derives Schema

object A {
  def apply(i: Int): A =
    A(
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString,
      i.toString
    )
}

This fails to compile with:

value derived is not a member of object zio.schema.Schema.
An extension method was tried, but could not be fully constructed:

    ???

    failed with:

        Exception occurred while executing macro expansion.
        java.lang.AssertionError: assertion failed: The symbol `apply` is overloaded. The method Select.unique can only be used for non-overloaded symbols.
        	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        	at scala.quoted.runtime.impl.QuotesImpl$reflect$Select$.unique(QuotesImpl.scala:536)
        	at scala.quoted.runtime.impl.QuotesImpl$reflect$Select$.unique(QuotesImpl.scala:534)
        	at zio.schema.DeriveSchema.appliedConstructor$1(DeriveSchema.scala:281)
        	at zio.schema.DeriveSchema.$anonfun$47$$anonfun$1(DeriveSchema.scala:285)
        	at zio.schema.DeriveSchema.$anonfun$47(DeriveSchema.scala:285)
        	at zio.schema.DeriveSchema.$anonfun$adapted$18(DeriveSchema.scala:285)
        	...

For case classes with 22 or less fields, there is no error even though there is an overloaded apply.
Is there any way to bypass this limitation?

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