-
Notifications
You must be signed in to change notification settings - Fork 1.1k
More strange behavior with derivation mirrors #7050
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
Comments
Also: def weird = {
val m = the[Mirror.ProductOf[Foo]]
// type R = m.MirroredElemTypes
val mRes = the[Mirror.ProductOf[(Int, String)]]
given mt as Mirror.ProductOf[m.MirroredElemTypes] = mRes
} Says: -- [E045] Cyclic Error: ../pg/Main.scala:30:31 ---------------------------------
30 | given mt as Mirror.ProductOf[m.MirroredElemTypes] = mRes
| ^
| Recursive value m needs type
longer explanation available when compiling with `-explain`
one error found |
I agree the error message is a bit confusing, but it's nothing to do with class Foo[A] {
type T
}
given as Foo[Unit] {
type T = Int
}
given as Foo[Int] {
type T = Boolean
}
def foo = {
val f = the[Foo[Unit]]
type T = f.T
val g = the[Foo[Int]]
given as Foo[f.T] = g
} Yields the same error,
|
I don't know if this is useful but you can still recover functionality with a closure import scala.deriving._
case class Foo(x: Int, y: String)
inline def locally[T](body: => T): T = body
def weird = {
val m = the[Mirror.ProductOf[Foo]]
type R = m.MirroredElemTypes
val mRes = the[Mirror.ProductOf[(Int, String)]]
locally {
given mt as Mirror.ProductOf[R] = mRes
}
} |
Possibly related: def (p: P) toTuple[P <: Product] given (m: scala.derivation.Mirror.ProductOf[P]): m.MirroredElemTypes =
Tuple.fromArray(p.productIterator.toArray).asInstanceOf[m.MirroredElemTypes] Gives: [error] -- [E047] Cyclic Error: /Users/anatolii/Projects/dotty/dotty/library/src/dotty/DottyPredef.scala:41:45
[error] 41 | def (p: P) toTuple[P <: Product] given (m: scala.derivation.Mirror.ProductOf[P]): m.MirroredElemTypes =
[error] | ^
[error] | Cyclic reference involving implicit value m
[error] one error found |
It does look like the above one is mirror-specific... The following works: class Foo[A] {
type T
}
def (p: P) toTuple[P <: Product] given (m: Foo[P]): m.T =
??? The following works as well: class Foo {
type T
}
type Bar[X] = Foo { type T = X; type Y <: Tuple }
def (p: P) toTuple[P <: Product] given (m: Bar[P]): m.Y =
??? However, the following fails: def (p: P) toTuple[P <: Product] given (m: scala.derivation.Mirror.ProductOf[P]): m.MirroredElemTypes =
??? Error: -- [E047] Cyclic Error: ../pg/Main.scala:1:43 ----------------------------------
1 |def (p: P) toTuple[P <: Product] given (m: scala.derivation.Mirror.ProductOf[P]): m.MirroredElemTypes =
| ^
| Cyclic reference involving implicit value m @milessabin do you think I am missing something here? |
Further minimizes to: def f[P](p: P) given (m: scala.derivation.Mirror.Of[P]): Any = ??? -- [E047] Cyclic Error: ../pg/Main.scala:1:25 ----------------------------------
1 |def f[P](p: P) given (m: scala.derivation.Mirror.Of[P]): Any = ???
| ^
| Cyclic reference involving implicit value m
longer explanation available when compiling with `-explain`
one error found |
Ok, nvm: def f[P](p: P) given (m: scala.deriving.Mirror.Of[P]): Any = ??? Typo: |
The confusing error messages are a problem. There's really nothing special about a |
The reason I'm fast to blame mirrors is because their instances are synthetic. I can't treat them as ordinary implicits when I see fishy things like cyclic references. You're right though, these errors seem to be unrelated to mirrors. |
Says:
To make it compile:
The text was updated successfully, but these errors were encountered: