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

existential type in patmat causes cast that breaks @tailrec #6145

Closed
scabug opened this issue Jul 26, 2012 · 9 comments
Closed

existential type in patmat causes cast that breaks @tailrec #6145

scabug opened this issue Jul 26, 2012 · 9 comments

Comments

@scabug
Copy link

@scabug scabug commented Jul 26, 2012

This code works for Scala 2.10.0-M2, causes warning for 2.10.0-M3, and does not work for 2.10.0-M4, 2.10.0-M5, 2.10.0-M6, and 2.10.0-M7

  private val ParentPackagePattern = """^(?:(.*)\.|)\w+$"""r

  @annotation.tailrec
  final def searchClass(packageName: String,
                        className: String): Class[_] = {
    packageName match {
      case null | "" =>
        Class.forName(className)
      case ParentPackagePattern(parentPackageName) =>
        try {
          return Class.forName(packageName + "." + className)
        } catch {
          case e: ClassNotFoundException =>
        }
        searchClass(parentPackageName, className)
      case _ =>
        throw new IllegalArgumentException("Bad package name: " + packageName)
    }
  }
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 26, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6145?orig=1
Reporter: @Atry
Affected Versions: 2.10.0-M3, 2.10.0-M4, 2.10.0-M5, 2.10.0-M6

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 26, 2012

@VladUreche said (edited on Jul 26, 2012 12:47:03 PM UTC):
What is the error message? Can it be related to SI-4649?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 26, 2012

@VladUreche said:
Adriaan, since this is a regression, it should be critical, right?

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 26, 2012

@adriaanm said:

object Test {
  // the existential causes a cast and the cast makes searchClass not be in tail position
  // can we get rid of the useless cast?
  @annotation.tailrec
  final def searchClass: Class[_] = {
    "packageName" match {
      case _ =>
        searchClass
    }
  }
}
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 7, 2012

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 23, 2012

@Atry said (edited on Aug 23, 2012 12:58:39 AM UTC):
The origin test case still cannot be compiled for Scala 2.10.0-M7

@scabug scabug closed this Aug 28, 2012
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 4, 2012

@adriaanm said:
there were two problems with the original test: one was fixed (the existential type that made a tail position into a non-tail position), the other is not a regression: the try/catch with the return was never supported by tailcalls. Here's a simpler (yet isomorphic) test case that does not work on 2.9 nor 2.10:

 @annotation.tailrec
 final def searchClass: String = {
   "x" match {
     case null =>
       try {
         ""
       } catch {
         case e: ClassNotFoundException =>
          searchClass
       }
   }
 }
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 4, 2012

@adriaanm said:
I'm not sure we can support tail calls in try/catches or mixed with return statements. Please open a separate ticket for that if the improvement is important to you. Thank you!

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 5, 2012

@Atry said:
The try/catch issue is also a regression. I open another ticket here: #6479

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.