Skip to content
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

Tuple pattern > 22 elems casts argument before calling unapply #16213

Closed
bishabosha opened this issue Oct 19, 2022 · 1 comment · Fixed by #16248
Closed

Tuple pattern > 22 elems casts argument before calling unapply #16213

bishabosha opened this issue Oct 19, 2022 · 1 comment · Fixed by #16248

Comments

@bishabosha
Copy link
Member

bishabosha commented Oct 19, 2022

Compiler version

3.2.0, 3.2.2-RC1-bin-20221017-b88aa12-NIGHTLY-git-b88aa12

Minimized code

(1: Any) match
  case (_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_) => ???
  case _ => println("not tuple xxl")

Output

java.lang.ClassCastException: java.lang.Integer cannot be cast to scala.runtime.TupleXXL
  ... 32 elided

Expectation

no error, output not tuple xxl

@bishabosha bishabosha added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 19, 2022
@bishabosha
Copy link
Member Author

bishabosha commented Oct 19, 2022

looking at further desugaring of the match, we get to the point where we desugar to the if then else form, and see that there is a cast to TupleXXL:

matchResult1[Unit]: 
{
  case val x1: Any = 1:Any
  if x1.$asInstanceOf[Object].ne(null) then 
    {
      case val x2: Option[Seq[Any]] = 
        scala.runtime.TupleXXL.unapplySeq(
          x1.$asInstanceOf[runtime.TupleXXL] // Why do we cast `Any` to `TupleXXL`?
        )
      if x2.isEmpty.unary_! then 
        {
          case val x3: Seq[Any] = x2.get
          if x3.lengthCompare(23).==(0) then 
            {
              case val x4: Any = x3.apply(0)
              case val x5: Any = x3.apply(1)
              case val x6: Any = x3.apply(2)
              case val x7: Any = x3.apply(3)
              case val x8: Any = x3.apply(4)
              case val x9: Any = x3.apply(5)
              case val x10: Any = x3.apply(6)
              case val x11: Any = x3.apply(7)
              case val x12: Any = x3.apply(8)
              case val x13: Any = x3.apply(9)
              case val x14: Any = x3.apply(10)
              case val x15: Any = x3.apply(11)
              case val x16: Any = x3.apply(12)
              case val x17: Any = x3.apply(13)
              case val x18: Any = x3.apply(14)
              case val x19: Any = x3.apply(15)
              case val x20: Any = x3.apply(16)
              case val x21: Any = x3.apply(17)
              case val x22: Any = x3.apply(18)
              case val x23: Any = x3.apply(19)
              case val x24: Any = x3.apply(20)
              case val x25: Any = x3.apply(21)
              case val x26: Any = x3.apply(22) 
              return[matchResult1] 
                {
                  ???
                }
            }
            else ()
        }
        else ()
    }
    else ()
  return[matchResult1] 
    {
      println("not tuple xxl")
    }
}

@bishabosha bishabosha added area:pattern-matching and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 19, 2022
@dwijnand dwijnand self-assigned this Oct 20, 2022
@dwijnand dwijnand linked a pull request Oct 25, 2022 that will close this issue
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants