Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any limitation on the pattern matching number of scala?

I meet a weird problem of pattern matching in scala. The following code will complain compilation error. But if I remove one case statement, it will compile successfully. So there're two things confused me. One is that it looks like the the maximum pattern matching number of scala is 9. Another thing is the error message, I did not use sbt in this project, I use it in another project. Anyone can help me ?

The SBT builder crashed while compiling your project. This is a bug in the Scala compiler or SBT. Check the Erorr Log for details. The error message is: ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 38092 scala Unknown Scala Problem

 def main(args: Array[String]) {
    val list = List(1, 2, 3)

    import scala.collection.JavaConversions._
    val pattern_1 = """1""".r
    val pattern_2 = """1""".r
    val pattern_3 = """1""".r
    val pattern_4 = """1""".r
    val pattern_5 = """1""".r
    val pattern_6 = """1""".r
    val pattern_7 = """1""".r
    val pattern_8 = """1""".r
    val pattern_9 = """1""".r
    val pattern_10 = """1""".r

    "ffd,fa".split(",") foreach {
      case pattern_1() =>
      case pattern_2() =>
      case pattern_3() =>
      case pattern_4() =>
      case pattern_5() =>
      case pattern_6() =>
      case pattern_7() =>
      case pattern_8() =>
      case pattern_9() =>
    }
  }
like image 390
zjffdu Avatar asked Mar 19 '12 11:03

zjffdu


1 Answers

Yes. There is a limit to the number of cases. However, I believe that this will be fixed with the new virtual pattern matcher in 2.10.

The easiest way around the problem is just to split your pattern match up into multiple nested levels of matches.

like image 67
dhg Avatar answered Sep 27 '22 20:09

dhg