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

SI-7433 Fix spurious warning about catching control throwable #2653

Merged
merged 1 commit into from Jun 24, 2013

Conversation

retronym
Copy link
Member

In the same vein as SI-6994, such warnings should only be run
in the typer phase, and not in later typechecking (usually in
erasure.)

Why? After translation of pattern matching, we end up with:

case (ex8 @ _) => {
<synthetic> val x5: Throwable = ex8;
case11(){
  if ({
    case14(){
      if (x5.$isInstanceOf[NullPointerException]())
        matchEnd13(true)
      else
        case15()
    };
    case15(){
      if (x5.$isInstanceOf[RuntimeException]())
        matchEnd13(true)
      else
        case16()
    };
    case16(){
      matchEnd13(false)
    };
    matchEnd13(x: Boolean){
      x
    }
  })

Review by @gkossakowski

@ghost ghost assigned gkossakowski Jun 13, 2013
@gkossakowski
Copy link
Member

@retronym: it seems like you have a real test failure:

/localhome/jenkins/b/workspace/pr-rangepos-per-commit/test/build-partest.xml:17: java.lang.RuntimeException: Test suite finished with 1 case failing:
fail - neg/nonlocal-warning.scala  [output differs]% scalac nonlocal-warning.scala
nonlocal-warning.scala:4: warning: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
    catch { case x => 11 }
                 ^
error: No warnings can be incurred under -Xfatal-warnings.
one warning found
one error found

% diff /localhome/jenkins/b/workspace/pr-rangepos-per-commit/test/files/neg/nonlocal-warning-neg.log /localhome/jenkins/b/workspace/pr-rangepos-per-commit/test/files/neg/nonlocal-warning.check
@@ -1,6 +1,9 @@
 nonlocal-warning.scala:4: warning: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
     catch { case x => 11 }
                  ^
+nonlocal-warning.scala:2: warning: catch block may intercept non-local return from method foo
+  def foo(l: List[Int]): Int = {
+                               ^
 error: No warnings can be incurred under -Xfatal-warnings.
-one warning found
+two warnings found

@gkossakowski
Copy link
Member

Please reopen once the test failure is addressed.

In the same vein as SI-6994, we have to be careful not to warn
about synthetic code. In that case, the spurious warnings came
because we warned in the typechecker, which was also called in
erasure. In this case, we are issuing the warning in Uncurry,
so we must be mindful of the pattern matchers translations of
non-trivial catch patterns, which look like:

    case (ex8 @ _) => {
    <synthetic> val x5: Throwable = ex8;
    case11(){
      if ({
        case14(){
          if (x5.$isInstanceOf[NullPointerException]())
            matchEnd13(true)
          else
            case15()
        };
        case15(){
          if (x5.$isInstanceOf[RuntimeException]())
            matchEnd13(true)
          else
            case16()
        };
        case16(){
          matchEnd13(false)
        };
        matchEnd13(x: Boolean){
          x
        }
      })

This commit detects that `ex8` is synthetic and disables the warning.
@retronym retronym reopened this Jun 23, 2013
@retronym
Copy link
Member Author

@gkossakowski This patch has a better shot at correctness

@gkossakowski
Copy link
Member

LGTM.

gkossakowski added a commit that referenced this pull request Jun 24, 2013
SI-7433 Fix spurious warning about catching control throwable
@gkossakowski gkossakowski merged commit b29e515 into scala:master Jun 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants