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

funny match error kills REPL (and Play request) #8051

Closed
scabug opened this issue Dec 8, 2013 · 7 comments
Closed

funny match error kills REPL (and Play request) #8051

scabug opened this issue Dec 8, 2013 · 7 comments
Assignees

Comments

@scabug
Copy link

scabug commented Dec 8, 2013

The REPL normally catches exceptions:

scala> case object A { override def toString = ??? }
scala> A
scala.NotImplementedError: an implementation is missing
scala>

MatchError is fine too:

scala> object B { override def toString = ("str":Any) match { case 1 => "ok" } }
defined module B

scala> B
scala.MatchError: str (of class java.lang.String)

scala>

but not this MatchError:

scala> :paste
// Entering paste mode (ctrl-D to finish)

trait X {
  override def toString = this match{
    case Z(z) => z.toString
  }
}
case class Y(y: Int) extends X
case class Z(z: Int) extends X

// Exiting paste mode, now interpreting.

defined trait X
defined class Y
defined class Z

scala> Y(0)
Exception in thread "main" 
Exception: scala.MatchError thrown from the UncaughtExceptionHandler in thread "main"
12:01 morbo:~ $ 

Any ideas?

@scabug
Copy link
Author

scabug commented Dec 8, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8051?orig=1
Reporter: @refried
Affected Versions: 2.10.3
Duplicates #7912

@scabug
Copy link
Author

scabug commented Dec 9, 2013

@jroper said:
Problem here seems to be that MatchError.getMessage is throwing itself again:

Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

trait X {
  override def toString = this match{
    case Z(z) => z.toString
  }
}
case class Y(y: Int) extends X
case class Z(z: Int) extends X

try { 
  Y(0).toString
} catch {
  case e: Exception =>
    try {
      e.getMessage
    } catch {
      case t: Exception => "Exception.getMessage threw the following exception: " + t.getClass
    }
}

// Exiting paste mode, now interpreting.

defined trait X
defined class Y
defined class Z
res0: String = Exception.getMessage threw the following exception: class scala.MatchError

Anything that attempts to report anything about this error will itself throw an exception when it tries to call getMessage, and since getMessage is rethrowing the exception, this will defeat every single layer of error reporting.

@scabug
Copy link
Author

scabug commented Dec 9, 2013

@jroper said:
Related Play issue:

playframework/playframework#2138

@scabug
Copy link
Author

scabug commented Dec 9, 2013

@refried said (edited on Dec 9, 2013 4:35:20 AM UTC):
Thanks for digging into that.

I'm guessing it's not re-throwing it per se, but trying to print the expression that failed to match; but printing the expression is what causes the match failure.

@scabug scabug closed this as completed Dec 9, 2013
@scabug
Copy link
Author

scabug commented Dec 9, 2013

@retronym said:
Duplicate of #7912

@scabug
Copy link
Author

scabug commented Dec 10, 2013

@jroper said:
I should have realised this was a duplicate of a bug that I myself reported!

@scabug
Copy link
Author

scabug commented Dec 10, 2013

@refried said:
Yeah, I wasn't expecting that either.

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

No branches or pull requests

2 participants