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

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

Closed
scabug opened this issue May 11, 2011 · 4 comments
Closed

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

scabug opened this issue May 11, 2011 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 11, 2011

=== 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.

@scabug
Copy link
Author

scabug commented May 11, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4568?orig=1
Reporter: Scott Morrison (scottmorrison)

@scabug
Copy link
Author

scabug commented May 11, 2011

Scott Morrison (scottmorrison) said:
Oops, sorry about the broken use of

 above. I'm not sure how to edit.

@scabug
Copy link
Author

scabug commented May 6, 2012

@retronym said:
scala/scala#480

@scabug
Copy link
Author

scabug commented May 7, 2012

@retronym said:
scala/scala@538e6df

@scabug scabug closed this as completed May 7, 2012
@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants