Skip to content

Unsoundness with Mirrors: it is possible to summon a mirror with an incorrect MirrorElemTypes of your choice #7380

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

Example

import scala.deriving.Mirror

@main def Test =
  val mrr = summon[Mirror.Of[(Int, String)] { type MirroredElemTypes = (Int, Int, Int) }]
  val ev1 = summon[(Int, Int, Int) =:= mrr.MirroredElemTypes]
  val ev2 = summon[(Int, String) =:= mrr.MirroredElemTypes]
  // val ev3 = summon[(Int, String) =:= (Int, Int, Int)]  // Implicit not found (correct, but breaks transitivity)

  val tup: (Int, String) = (1, "foo")
  val res: mrr.MirroredElemTypes = tup

Run it:

Exception in thread "main" java.lang.ClassCastException: scala.Tuple2 cannot be cast to scala.Tuple3
	at Test$package$.Test(Test.scala:10)
	at Test.main(Test.scala:3)

Expectation

I would expect mrr to be impossible to summon because of the bad refinement type.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions