Skip to content

Summon does not work for derived TypeClass if global given is used #11563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hombre opened this issue Mar 1, 2021 · 1 comment · Fixed by #11610
Closed

Summon does not work for derived TypeClass if global given is used #11563

hombre opened this issue Mar 1, 2021 · 1 comment · Fixed by #11610

Comments

@hombre
Copy link

hombre commented Mar 1, 2021

Compiler version

3.0.0-RC1

Minimized code

import scala.compiletime.{constValue, erasedValue, summonInline}
import scala.deriving.Mirror

trait Printer[T]:
  def format: String

given Printer[String] with
  def format: String = "String"

inline given[T](using mirror: Mirror.ProductOf[T]): Printer[T] = Printer.derived[T]

object Printer:
  inline def apply[T](using printer: Printer[T]): Printer[T] = printer

  inline def derived[T](using mirror: Mirror.ProductOf[T]): Printer[T] =
    val params = summonPrinters[mirror.MirroredElemTypes]
    new Printer[T] :
      def format: String = params.map(p => p.format).mkString(",")

inline def summonPrinters[Types <: Tuple]: Seq[Printer[?]] = inline erasedValue[Types] match
  case _: EmptyTuple => Seq.empty
  case _: (v *: vs) => summonInline[Printer[v]] +: summonPrinters[vs]

case class Simple(name: String)

object Main:
  def main(args: Array[String]): Unit =
    assert(Printer[String].format == "String")
    assert(Printer[Simple].format == "String")

Output

error] -- Error: /<redacted>/Test.scala:35:26 
[error] 35  |    assert(Printer[Simple].format == "String")
[error]    |                          ^
[error]    |              cannot reduce summonFrom with
[error]    |               patterns :  case t @ _:Printer[String]
[error] one error found
[error] one error found

Expectation

Code can be compiled. As it does for version 3.0.0-M3

@deusaquilus
Copy link
Contributor

deusaquilus commented Mar 5, 2021

@nicolasstucki Wait... my previous comment was wrong.
I think #11557 also fixes this issue. I just tried this code with 3.0.0-RC2-bin-20210304-5fa55b1-NIGHTLY and it worked!

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 5, 2021
Closes scala#11563
Possibly fixed by scala#11557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants