Skip to content

Mirror.Of is not implemented for named tuples #22382

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
smarter opened this issue Jan 15, 2025 · 4 comments · Fixed by #22469
Closed

Mirror.Of is not implemented for named tuples #22382

smarter opened this issue Jan 15, 2025 · 4 comments · Fixed by #22469
Assignees
Labels
area:named-tuples Issues tied to the named tuples feature. area:typeclass-derivation itype:bug
Milestone

Comments

@smarter
Copy link
Member

smarter commented Jan 15, 2025

Compiler version

3.6.2

Minimized code

import scala.language.experimental.namedTuples
import scala.deriving.*

summon[Mirror.Of[(Int, String)]] // OK

summon[Mirror.Of[(foo: Int, bla: String)]] // error

Output

  |No given instance of type scala.deriving.Mirror.Of[(foo : Int, bar : String)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type scala.deriving.Mirror.Of[(foo : Int, bar : String)]:
  |     * class Any is not a generic product because it is not a case class
  |     * class Any is not a generic sum because it is not a sealed class

Expectation

Just like regular tuples, named tuples should have mirror instances because they are product types and mirrors allow for uniform meta-programming on sums and products types.

@smarter smarter added area:named-tuples Issues tied to the named tuples feature. itype:bug labels Jan 15, 2025
@bishabosha
Copy link
Member

bishabosha commented Jan 24, 2025

the contract for Mirror is "def m[T](foo: T)(using Mirror.ProductOf[T]) = foo.asInstanceOf[Product] doesnt crash" so this can work

@bishabosha
Copy link
Member

bishabosha commented Jan 31, 2025

@jchyb I guess it wont be much extra to introduce mirror for Tuple>22 (if we forgive that _N methods don't exist)

@jchyb
Copy link
Contributor

jchyb commented Jan 31, 2025

Ah, sure. I forgot about that. I'll look into it

@bishabosha
Copy link
Member

bishabosha commented Jan 31, 2025

should probably put in the docs also that the MirroredLabel and MirroredElemLabels are for disambiguation/serialisation/pretty-printing purposes only, and don't necessarily correspond to a field/class that java reflection can access

@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:named-tuples Issues tied to the named tuples feature. area:typeclass-derivation itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants