-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inline match does not work on List
#8103
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
It would require an class Test {
inline def test(inline cs: List[Int]) <: Any =
inline cs match
case 1 :: Nil => 1
test(1 :: Nil)
test(List(1))
}
|
Hi @nicolasstucki, |
Should we close this? |
I just tested on master and it seems to still fail :( scala> class Test {
| inline def test(inline cs: List[Int]) <: Any =
| inline cs match
| case 1 :: Nil => 1
|
| test(1 :: Nil)
| test(List(1))
| }
6 | test(1 :: Nil)
| ^^^^^^^^^^^^^^
| cannot reduce inline match with
| scrutinee: {
| Nil.::[Int](1)
| } : List[Int]
| patterns : case ::.unapply[Int](1, Nil):::[Int]
| This location contains code that was inlined from rs$line$1:3
Am I missing something ? |
If I remember correctly, all inline pattern matching works based on scrutinee type, not the "shape" of the argument. Here the type of the scrutinee is |
@AleksanderBG I don't understand what you mean by |
@jto to make it work, you mean? The below code works: scala> class Test {
| inline def test(inline cs: List[Int]) <: Any =
| inline cs match
| case 1 :: _ => 1
|
| val i: 1 = test(new ::[1](1, Nil))
| }
// defined class Test And so does the following: scala> class Test {
| inline def test(inline cs: List[Int]) <: Any =
| inline cs match
| case _ :: _ => 1
|
| val i: 1 = test(new ::(1, Nil))
| }
// defined class Test But neither of the below: scala> class Test {
| inline def test(inline cs: List[Int]) <: Any =
| inline cs match
| case _ :: Nil => 1
|
| val i: 1 = test(new ::(1, Nil))
| }
6 | val i: 1 = test(new ::(1, Nil))
| ^^^^^^^^^^^^^^^^^^^^
| cannot reduce inline match with
| scrutinee: {
| new ::[Int](1, Nil)
| } : ::[Int]
| patterns : case ::.unapply[Int](_, Nil):::[Int]
| This location contains code that was inlined from rs$line$3:3
scala> class Test {
| inline def test(inline cs: List[Int]) <: Any =
| inline cs match
| case 1 :: _ => 1
|
| val i: 1 = test(new ::(1, Nil))
| }
6 | val i: 1 = test(new ::(1, Nil))
| ^^^^^^^^^^^^^^^^^^^^
| cannot reduce inline match with
| scrutinee: {
| new ::[Int](1, Nil)
| } : ::[Int]
| patterns : case ::.unapply[Int](1, _):::[Int]
| This location contains code that was inlined from rs$line$3:3 It's clear to us that inline patmat semantics are a bit confusing, but it's just that no one got to improving this part yet. |
Okay I understand now. Thanks for the examples. |
Closing as a duplicate of #6781. |
The following example was tested in a worksheet, created from
dotty-example-project
(commitb135f5a
) and Dotty0.21.0-RC1
minimized code
expectation
in the given example, the first case should be matched and the value
1
of type1
should be inlined.The text was updated successfully, but these errors were encountered: