-
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
Regression in match types combined with type lambda #19710
Comments
Maybe @sjrd could take a look. |
I believe this is as expected given the current subtyping rules for match types. type HasFoo[X] <: Boolean = X match {
case "foo" => true
case _ => false
}
type HasBar[X] = X match {
case "bar" => true
case _ => false
}
type F1 = Tuple.Filter[(1, "foo", 2, "bar"), HasFoo] // Ok
type F2 = Tuple.Filter[(1, "foo", 2, "bar"), HasBar] // Error |
@EugeneFlesselle I was the one who originally posted the question in scala-users discourse. I am aware that the "standard" match type above works and agree with you. However, I am using a type lambda that takes in a type parameter. So my question is, how do I add the upper bound in this case? I have tried the obvious, but that does not seem to work. TIA |
@hmf Unfortunately, upper bounds are simply not supported for type lambdas. In fact, I think they can only appear in an alias for a match type, as they can be necessary when defining recursive match types. So in this case you are forced to use type aliases, ending up with something like: type HasName2[N] = [M] =>> HasName3[N, M]
type HasName3[N, M] <: Boolean = M match
case N => true
case M => false
summon[Tuple.Filter[(1, "foo", 2, "bar"), HasName2["foo"]] =:= Tuple1["foo"]] // Ok |
It's also debatable whether the parameter type Filter1[T <: Tuple, P[_]] = T match
case EmptyTuple => EmptyTuple
case h *: t => P[h] match
case true => h *: Filter1[t, P]
case false => Filter1[t, P]
summon[Filter1[(1, "foo", 2, "bar"), HasName1["foo"]] =:= Tuple1["foo"]] // Ok |
@EugeneFlesselle Thanks for the information. Your type alias solution is ok for me. As for the |
Based on forum post: https://users.scala-lang.org/t/scala-3-how-do-we-make-a-lambda-type-conform-to-a-subtype/9805
Compiler version
3.3.1
Last good release: 3.3.1-RC1-bin-20230514-b0ccf40-NIGHTLY
First bad release: 3.3.1-RC1-bin-20230515-22b2259-NIGHTLY
Bisect points to d1d6c2e
Minimized code
Output
Expectation
Should comile (probably)
The text was updated successfully, but these errors were encountered: