Skip to content

can't summon mirror for MirroredElemTypes as it is generic tuple #7049

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
anatoliykmetyuk opened this issue Aug 15, 2019 · 3 comments · Fixed by #15250
Closed

can't summon mirror for MirroredElemTypes as it is generic tuple #7049

anatoliykmetyuk opened this issue Aug 15, 2019 · 3 comments · Fixed by #15250

Comments

@anatoliykmetyuk
Copy link
Contributor

anatoliykmetyuk commented Aug 15, 2019

import scala.deriving._

case class Foo(x: Int, y: String)

def toTuple[T <: Product](x: T)(using m: Mirror.ProductOf[T], mt: Mirror.ProductOf[m.MirroredElemTypes]) =
  mt.fromProduct(x)

def weird = {
  val m = summon[Mirror.ProductOf[Foo]]
  val mt1 = summon[Mirror.ProductOf[(Int, String)]]
  type R = (Int, String)
  val mt2 = summon[Mirror.ProductOf[R]]
  val mt3 = summon[Mirror.ProductOf[m.MirroredElemTypes]]

  val f = Foo(1, "foo")
  val g: (Int, String) = toTuple(f)// (using m, mt1)
}

Says:

-- Error: ../pg/Main.scala:20:54 -----------------------------------------------
20 |  val mt3 = the[Mirror.ProductOf[m.MirroredElemTypes]]
   |                                                      ^
   |no implicit argument of type deriving.Mirror.ProductOf[m.MirroredElemTypes] was found for parameter x of method the in object DottyPredef
-- Error: ../pg/Main.scala:23:35 -----------------------------------------------
23 |  val g: (Int, String) = toTuple(f)// given (m, mt1)
   |                                   ^
   |no implicit argument of type deriving.Mirror.ProductOf[m.MirroredElemTypes] was found for parameter mt of method toTuple
two errors found

That is, we can resolve the mirror of the tuple, but not if it is obtained from another mirror. To make it work:

def weird = {
  val m = the[Mirror.ProductOf[Foo]]
  val mt1 = the[Mirror.ProductOf[(Int, String)]]
  type R = (Int, String)
  val mt2 = the[Mirror.ProductOf[R]]
  // val mt3 = the[Mirror.ProductOf[m.MirroredElemTypes]]

  val f = Foo(1, "foo")
  val g: (Int, String) = toTuple(f) given (m, mt1)
}
@milessabin
Copy link
Contributor

I think you're experiencing some strange implicit/given scope related issues rather than anything specific to Mirror ... see my comments on #7050.

@odersky odersky added the backlog No work planned on this by the core team for the time being. label Apr 5, 2022
@bishabosha bishabosha removed backlog No work planned on this by the core team for the time being. labels May 20, 2022
@bishabosha
Copy link
Member

bishabosha commented May 20, 2022

I think this is caused by #14127, since we improved error messages, they now show class *: is not a generic product because it is not a case class, full output here:

-- Error: ----------------------------------------------------------------------
13 |  val mt3 = summon[Mirror.ProductOf[m.MirroredElemTypes]]
   |                                                         ^
   |No given instance of type deriving.Mirror.ProductOf[m.MirroredElemTypes] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.ProductOf[m.MirroredElemTypes]: class *: is not a generic product because it is not a case class
-- Error: ----------------------------------------------------------------------
16 |  val g: (Int, String) = toTuple(f)// (using m, mt1)
   |                                   ^
   |No given instance of type deriving.Mirror.ProductOf[(Int, String)] was found for parameter mt of method toTuple. Failed to synthesize an instance of type deriving.Mirror.ProductOf[(Int, String)]: class *: is not a generic product because it is not a case class
2 errors found

@bishabosha

This comment was marked as duplicate.

@bishabosha bishabosha changed the title Strange behavior with derivation mirrors can't summon mirror for MirroredElemTypes May 20, 2022
@bishabosha bishabosha changed the title can't summon mirror for MirroredElemTypes can't summon mirror for MirroredElemTypes as it is generic tuple May 20, 2022
@bishabosha bishabosha added this to the 3.2.0-RC1 milestone May 24, 2022
@Kordyjan Kordyjan modified the milestones: 3.2.0-RC1, 3.2.0 Aug 1, 2023
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.

5 participants