-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inconsistent compilation results in mirror-deriving code #13001
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
Labels
Milestone
Comments
I'm unlikely to have time to pursue this and minimize it |
This seems to be a separate compilation issue related to opaque types. I reduced the example project to the following self-contained test case, which succeeds with joint compilation but fails separate compilation. Main_1.scalacase class Foo(a: String)
trait Arbitrary[T]
trait Gen[+T]
object ArbitraryDerivation:
given deriveArb[A](using gen: DerivedGen[A]): Arbitrary[A] = ???
opaque type DerivedGen[A] = Gen[A]
object DerivedGen extends DerivedGenInstances
sealed abstract class DerivedGenInstances:
inline given derived[A](using gen: K0.Generic[A]): DerivedGen[A] =
val dummy: DerivedGen[A] = ???
gen.derive(dummy, dummy)
// from shapeless3-deriving
import scala.deriving.*
object K0 {
type Kind[C, O] = C { type Kind = K0.type ; type MirroredType = O ; type MirroredElemTypes <: Tuple }
type Generic[O] = Kind[Mirror, O]
type ProductGeneric[O] = Kind[Mirror.Product, O]
type CoproductGeneric[O] = Kind[Mirror.Sum, O]
extension [F[_], T](gen: Generic[T])
inline def derive(f: => (ProductGeneric[T] & gen.type) ?=> F[T], g: => (CoproductGeneric[T] & gen.type) ?=> F[T]): F[T] =
inline gen match {
case p: ProductGeneric[T] => f(using p.asInstanceOf)
case c: CoproductGeneric[T] => g(using c.asInstanceOf)
}
} Test_2.scalaclass Test:
import ArbitraryDerivation.given
private def test[A: Arbitrary]: Unit = {}
test[Foo]
Separate compilation succeeds if the opqaue type is eliminated, e.g. -opaque type DerivedGen[A] = Gen[A]
+trait DerivedGen[A] |
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Jul 29, 2021
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Jul 30, 2021
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Jul 30, 2021
tanishiking
pushed a commit
to tanishiking/scala3
that referenced
this issue
Aug 10, 2021
smarter
pushed a commit
to dotty-staging/dotty
that referenced
this issue
Aug 11, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler version
3.0.0
Minimized code
Not minimized, but the
github4s
project at this specific commit:https://github.com/47degrees/github4s/tree/bab2cd491d948807d364fa73687138d35f9feb6c
Output
With the file: https://github.com/47degrees/github4s/blob/gb-scala3/github4s/src/test/scala/github4s/unit/EncoderDecoderSpec.scala#L83
I've observed three different, seemingly-unrelated behaviors so far:
test
invocations except the first one, compilation succeeds.test
invocations except the first two, compilation fails on both, with errors about not finding theMirror
:Compiler output
I've also tried with the first 10-20 or so uncommented, and it fails with those same
Mirror
errors on each.test
invocations, and try compiling the file as-is, compilation prints no output, the compiler never terminates (I've left it for >20 minutes), and it ignores ctrl-c inputsExpectation
If the code is correct, it should compile.
If it's incorrect, it should fail consistent, the compiler shouldn't run forever and be uncancelable.
Code that compiles without error should not start producing errors when an unrelated statement is added to the file.
The text was updated successfully, but these errors were encountered: