-
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
Intersection, match types and tuples don't work together #12800
Comments
Note that this encoding is unsafe, as was explained time and time again on the contributors forum. It seems this (sound) version works fine: type FieldType2[K, +V] = V with KeyTag2[K, V]
type KeyTag2[K, +V] |
@smarter would it be possible to detect such cases and warn about unsoundness in failure message? |
Not sure what you mean, the unsoudness @LPTK mentioned comes from using |
This is working as intended, the non-reducing case does not reduce because of the following line from the spec:
Here In the reducing cases (with |
Hmmm. I see. I managed to find a case where the code LPTK posted also does not reduce. Is it a bug that I found such a case then, or is it a bug that the code LPTK posted works here? I can't imagine both versions being valid. |
Can you send an updated example? (I'm really unfamiliar with this FieldType2/KeyTag2 encoding) |
object DoesntWork {
type FieldType[K, +V] = V with KeyTag[K, V]
type KeyTag[K, +V]
type ->>[K, +V] = FieldType[K, V]
type FindField[R <: scala.Tuple, K] = R match {
case FieldType[K, f] *: t => f
case _ *: t => FindField[t, K]
}
type R = ("A" ->> Int) *: ("B" ->> Double) *: ("C" ->> String) *: ("D" ->> Boolean) *: EmptyTuple
summon[FindField[R, "B"] =:= Double]
}
|
@Katrix we should certainly get to the bottom of your issue and determine if it should or shouldn't fail, but in the meantime I wonder why you wouldn't use a much simpler encoding for this thing you're trying to do. The following works: object MyLib:
opaque type FieldType[K, +V] = V
type KeyTag[K, +V]
type ->>[K, +V] = FieldType[K, V]
type FindField[R <: scala.Tuple, K] = R match
case FieldType[K, f] *: t => f
case _ *: t => FindField[t, K]
import MyLib._
object Works:
type R = ("A" ->> Int) *: ("B" ->> Double) *: ("C" ->> String) *: ("D" ->> Boolean) *: EmptyTuple
summon[FindField[R, "B"] =:= Double] |
@Katrix I don't think the compiler can safely conclude that |
Does |
It does yes, and what's currently used |
Fix #12800: Clarify match type reduction error on empty scrutinee
Compiler version 3.0.0
Seems the compiler doesn't like it when intersection, match types and tuples are used together. Yes, opaque types are a better match here, but need this for Shapeless, and don't want to break the API here.
Minimized code
Use only one definition of
WrapUpper
andWrap
in the below code. The one relying on tuples does not work, while the one using a sealed trait doesOutput
Expectation
It should compile. Putting the Extract and Wrap types closer together does work fine, which works counter to how I would expect them to work. Either none, or all.
The text was updated successfully, but these errors were encountered: