softwaremill/quicklens

Support generic type aliases that start with Option

Opened this issue · 2 comments

Avat-h commented

Let's consider case class containing optional wrapped generic field:

  case class Wrapper[T](value: T)
  case class X(f1: Option[Wrapper[String]])
  val x = X(Option(Wrapper("test")))
  modify(x)(_.f1.each.value).using(duplicate)

It works correctly.

But if we define generic type alias like that:

  case class Wrapper[T](value: T)
  type OptWrap[T] = Option[Wrapper[T]]
  case class X(f1: OptWrap[String])
  val x = X(Option(Wrapper("test")))
  modify(x)(_.f1.each.value).using(duplicate)

then it fails to compile with error:

value each is not a member of ModifyEachTest.this.OptWrap[String].
An extension method was tried, but could not be fully constructed:

    com.softwaremill.quicklens.each[[T] =>> Option[ModifyEachTest.this.Wrapper[T]],
      String](_$8.f1)(
      com.softwaremill.quicklens.QuicklensFunctor.given_QuicklensFunctor_M[K, M])

    failed with:

        No given instance of type com.softwaremill.quicklens.QuicklensFunctor[
          [T] =>> Option[ModifyEachTest.this.Wrapper[T]]] was found for an implicit parameter of method each in package com.softwaremill.quicklens.
        I found:
        
            com.softwaremill.quicklens.QuicklensFunctor.given_QuicklensFunctor_M[K, M]
        
        But given instance given_QuicklensFunctor_M in object QuicklensFunctor does not match type com.softwaremill.quicklens.QuicklensFunctor[
          [T] =>> Option[ModifyEachTest.this.Wrapper[T]]].
  modify(x)(_.f1.each.value).using(duplicate)

Is it possible to support such cases in quicklens?

adamw commented

This is Scala 3, right? I'd be guessing we're missing a .dealias somewhere, but I might be wrong ...

Avat-h commented

Both scala 3 and 2.13. I think it's not macro-related, but QuicklensFunctor must be defined differently. I tried to add such QuicklensFunctor implementation but failed.