Details

      Description

      The following macro throws a VerifyError when run. Variations on the error are possible. There need to be enough cases to cause a lookupswitch to be generated.

      import scala.reflect.makro.Context
      import language.experimental.macros
      
      object Macros {
        def m(): Unit = macro m_impl
        def m_impl(c: Context)(): c.Expr[Unit] = {
          import c.universe._
          def f(ch: Char): Any = ch match {
            case 'b' | 'B'                               => 1
            case 'c' | 'C'                               => 2
            case 'd' | 'u' | 'i' | 'o' | 'x' | 'X' | 'c' => 3
            case 'f' | 'e' | 'E' | 'g' | 'G'             => 4
            case 'h' | 'H'                               => 5
            case 's'                                     => 6
            case _                                       => 7
          }
          List('a') foreach f
          c.Expr[Unit](Block(Literal(Constant(()))))
        }
      }
      
      object Test extends App { Macros.m() }
      
      
      uncaught exception during compilation: java.lang.VerifyError
      error: java.lang.VerifyError: (class: Macros$, method: Macros$$f$1 signature: (C)Ljava/lang/Object;) Unsorted lookup switch
      	at java.lang.Class.forName0(Native Method)
      	at java.lang.Class.forName(Class.java:264)
      	at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroRuntime$2.loadMacroImpl$1(Macros.scala:702)
      	at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroRuntime$2.apply(Macros.scala:745)
      	at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroRuntime$2.apply(Macros.scala:653)
      	at scala.collection.mutable.MapLike$class.getOrElseUpdate(MapLike.scala:189)
      	at scala.collection.mutable.AbstractMap.getOrElseUpdate(Map.scala:91)
      	at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroRuntime(Macros.scala:653)
      

        Issue Links

          Activity

          Hide
          Adriaan Moors added a comment -

          I've looking at all of these unreachability tickets today and will continue tomorrow.
          No need for a separate ticket, Iulian, I'll take care of it.

          Yes, we shouldn't emit switches like this, and fall back.
          I wasn't dealing with alternatives properly in the code that collapses guarded cases in switches.

          Show
          Adriaan Moors added a comment - I've looking at all of these unreachability tickets today and will continue tomorrow. No need for a separate ticket, Iulian, I'll take care of it. Yes, we shouldn't emit switches like this, and fall back. I wasn't dealing with alternatives properly in the code that collapses guarded cases in switches.
          Hide
          Paul Phillips added a comment -

          > I'm trying to figure out how to consider reachability per alternative, but that's tricky to describe in general. What if you have several nested alternatives (inside other patterns) in one case?

          What deters you from expanding all the alternatives up front? This was something the old matcher did which I thought was approximately correct: copy patterns around until alternatives are gone.

          Show
          Paul Phillips added a comment - > I'm trying to figure out how to consider reachability per alternative, but that's tricky to describe in general. What if you have several nested alternatives (inside other patterns) in one case? What deters you from expanding all the alternatives up front? This was something the old matcher did which I thought was approximately correct: copy patterns around until alternatives are gone.
          Hide
          Adriaan Moors added a comment -

          it's an option I'm considering, at least for the sake of analyzing a match
          I currently didn't need to do that, since I could just Or the corresponding propositions together

          Show
          Adriaan Moors added a comment - it's an option I'm considering, at least for the sake of analyzing a match I currently didn't need to do that, since I could just Or the corresponding propositions together
          Show
          Adriaan Moors added a comment - https://github.com/scala/scala/pull/876
          Hide
          Jason Zaugg added a comment -

          A variation of this bug persisted, but has been fixed along with SI-6902

          Show
          Jason Zaugg added a comment - A variation of this bug persisted, but has been fixed along with SI-6902

            People

            • Assignee:
              Adriaan Moors
              Reporter:
              Paul Phillips
            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development