Scala Programming Language
  1. Scala Programming Language
  2. SI-4568

"Pimp my library" recursion can cause compiler crash (assertion error)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M3
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      === What steps will reproduce the problem ===
      Compile, under Scala 2.9.0.RC4 (and presumably earlier)

      object SubList {
             implicit def sublistable[A](x: List[A]) = new SubListable(x)
             class SubListable[A](x: List[A]) {
               def isSubListOf(y: List[A]) = {
                      x match {
                        case Nil => true
                        case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1)))
                      }
               }
             }
      }
      

      === What is the expected behavior? ===
      Some sort of error (e.g. along the lines of "recursive method isSubListOf requires a return type") presented to the user.

      === What do you see instead? ===
      The compiler crashes with an AssertionError, e.g.

      java.lang.AssertionError: assertion failed: y.indexOf(h).$$plus(1)
             at scala.Predef$$.assert(Predef.scala:103)
             at scala.tools.nsc.typechecker.SuperAccessors
      $$SuperAccTransformer.transform(SuperAccessors.scala:236)
             at scala.tools.nsc.typechecker.SuperAccessors$$SuperAccTransformer$$
      $$anonfun$$1.apply(SuperAccessors.scala:48)
             at scala.tools.nsc.typechecker.SuperAccessors$$SuperAccTransformer$$
      $$anonfun$$1.apply(SuperAccessors.scala:45)
             at scala.Tuple2$$Zipped$$$$anonfun$$map$$1.apply(Tuple2.scala:65)
             at scala.Tuple2$$Zipped$$$$anonfun$$map$$1.apply(Tuple2.scala:63)
             at scala.collection.LinearSeqOptimized
      $$class.foreach(LinearSeqOptimized.scala:59)
             at scala.collection.immutable.List.foreach(List.scala:45)
             at scala.Tuple2$$Zipped.map(Tuple2.scala:63)
             at scala.tools.nsc.typechecker.SuperAccessors
      $$SuperAccTransformer.transformArgs(SuperAccessors.scala:45)
             at scala.tools.nsc.typechecker.SuperAccessors
      $$SuperAccTransformer.transform(SuperAccessors.scala:237)
             at scala.tools.nsc.typechecker.SuperAccessors$$SuperAccTransformer$$
      $$anonfun$$transformArgs$$1.apply(SuperAccessors.scala:50)
      [...]
      Error during sbt execution: java.lang.AssertionError: assertion failed: y.indexOf(h).$$plus(1)
      

      === Additional information ===
      Originally posted at http://groups.google.com/group/scala-user/browse_thread/thread/42b042969c15a0a0

      I'm not saying that this code should compile; just that the compiler should identify an error in the source, rather than crashing.

        Activity

        Hide
        Scott Morrison added a comment -

        Oops, sorry about the broken use of <pre/> above. I'm not sure how to edit.

        Show
        Scott Morrison added a comment - Oops, sorry about the broken use of <pre/> above. I'm not sure how to edit.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/480
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/commit/538e6df

          People

          • Assignee:
            Iulian Dragos
            Reporter:
            Scott Morrison
            TracCC:
            Ismael Juma, Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development