-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Inline (not transparent) with match type alters typechecking #13250
Comments
Minimized import scala.deriving.Mirror
class MyGeneric[Repr]
type TransformTuple[T <: Tuple] <: Tuple = T match {
case x *: xs => x *: TransformTuple[xs]
case EmptyTuple => EmptyTuple
}
def myGeneric[T <: Product](using m: Mirror.ProductOf[T]): MyGeneric[TransformTuple[m.MirroredElemTypes]] = ???
inline def myGenericInline[T <: Product](using m: Mirror.ProductOf[T]): MyGeneric[TransformTuple[m.MirroredElemTypes]] = ???
def testGen = {
takesGen(myGeneric[(Int, String)])
// ^^^^^^^^^^^^^^^^^^^^^^^^
// Found: MyGeneric[Int *: String *: EmptyTuple]
// Required: MyGeneric[TransformTuple[?]]
//
// Note: a match type could not be fully reduced:
//
// trying to reduce TransformTuple[?]
// failed since selector Any
// does not match case x *: xs => x *: TransformTuple[xs]
// and cannot be shown to be disjoint from it either.
// Therefore, reduction cannot advance to the remaining case
//
// case EmptyTuple => EmptyTuple
takesGen(myGenericInline[(Int, String)])
}
def takesGen[Repr](mg: MyGeneric[Repr]): String = "Foo" |
This fails in typer before we inline the code. There must be some part of the logic of match types that does something different when seeing an inline definition. Both definitions should be typed the same way. |
Was told to mention that the Shapeless 2 port to Scala 3 needs this fixed. Currently most givens are defined as inline just incase, but would be nice to drop that |
Now it says: def testGen =
takesGen(myGeneric[(Int, String)])
// ^^^^^^^^^^^^^^^^^^^^^^^^
// Found: MyGeneric[Int *: String *: EmptyTuple]
// Required: MyGeneric[TransformTuple[Nothing]]
//
// Note: a match type could not be fully reduced:
//
// trying to reduce TransformTuple[Nothing]
// failed since selector Nothing
// is uninhabited (there are no values of that type).
takesGen(myGenericInline[(Int, String)]) .. which looks worst?
I assume we agree it should compile? I would hope so, but inline is the newer code branch, so I'd assume the non-inline path typer takes to less buggy... |
Compiler version
3.0.3-RC1-bin-20210803-010f8de-NIGHTLY
Minimized code
Note, the match type is required. Without it, everything works normally.
Output
Expectation
Inline without transparent should not change typechecking. In this case I'd expect both to compile, but only the inline one does.
The text was updated successfully, but these errors were encountered: