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

java.lang.VerifyError: Inconsistent stack height (simple for loop/ foreach) #5380

Closed
scabug opened this issue Jan 17, 2012 · 5 comments
Closed
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 17, 2012

This is a simple function:

def parse: Int = {
  var texts = Array("1","2","3","123")

  //either foreach or for(text <- texts) DO raise same exception
  texts.foreach{ text =>
    return try { text.toInt } catch { case _ => -1 }
  }
  0
}

Please do not mind about the purpose of the function. I tried but could not know how to code to show the purpose. I shortened it from my code.

The code can be compiled. It raises exception at runtime. I got this exception:

java.lang.VerifyError: (class: $anonfun$parse$1, method: apply signature: (Ljava/lang/String;)Lscala/runtime/Nothing$;) Inconsistent stack height 0 != 3
        at .parse(<console>:11)
        at .<init>(<console>:9)
        at .<clinit>(<console>)
        at .<init>(<console>:11)
        at .<clinit>(<console>)
        at $print(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
        at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
        at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
        at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
        at java.lang.Thread.run(Thread.java:722)

I guess this issue is similar to this one: #203

@scabug
Copy link
Author

scabug commented Jan 17, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5380?orig=1
Reporter: Hai Bison (haibison)
Assignee: @magarciaEPFL
Affected Versions: 2.9.1
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Jan 17, 2012

@scabug
Copy link
Author

scabug commented Jan 17, 2012

@magarciaEPFL said:
It's an "Attempt to enter try block with non-empty stack"

Input program:

  def main(args: Array[String]) { 
    for (x <- List(1))
      return try { 1 } catch { case _ => 0 }
    0
  }

After cleanup:

    @SerialVersionUID(0) final <synthetic> class $anonfun$main$1 extends scala.runtime.AbstractFunction1 with Serializable {

      final def apply(x: Int): Nothing = 
        throw new scala.runtime.NonLocalReturnControl(
          $anonfun$main$1.this.nonLocalReturnKey1$1, {
        var exceptionResult1: Object = _;
        try {
          exceptionResult1 = {
            1;
            scala.runtime.BoxedUnit.UNIT
          }
        } catch {
          case _ => {
            exceptionResult1 = {
              0;
              scala.runtime.BoxedUnit.UNIT
            }
          }
        };
        exceptionResult1
      });

      final <bridge> def apply(v1: Object): Object = $anonfun$main$1.this.apply(scala.Int.unbox(v1));

      <synthetic> <paramaccessor> private[this] val nonLocalReturnKey1$1: Object = _;
      def <init>(nonLocalReturnKey1$1: Object): anonymous class $anonfun$main$1 = {
        $anonfun$main$1.this.nonLocalReturnKey1$1 = nonLocalReturnKey1$1;
        $anonfun$main$1.super.<init>();
        ()
      }
    };

What Scala.Net emits:

.method public hidebysig virtual final instance class [mscorlib]System.Exception 
        apply(int32 x) cil managed
{
  // Code size       52 (0x34)
  .maxstack  2
  .locals init (object V_0)
  IL_0000:  ldarg.0
  IL_0001:  ldfld      object ABC$/$anonfun$main$1::nonLocalReturnKey1$1
  IL_0006:  ldnull
  IL_0007:  stloc.0
  .try
  {
    IL_0008:  ldc.i4.1
    IL_0009:  pop
    IL_000a:  ldsfld     class [scalalib]scala.runtime.BoxedUnit [scalalib]scala.runtime.BoxedUnit::UNIT
    IL_000f:  stloc.0
    IL_0010:  leave      IL_002d
    IL_0015:  leave      IL_002d
  }  // end .try
  catch [mscorlib]System.Exception 
  {
    IL_001a:  pop
    IL_001b:  ldc.i4.0
    IL_001c:  pop
    IL_001d:  ldsfld     class [scalalib]scala.runtime.BoxedUnit [scalalib]scala.runtime.BoxedUnit::UNIT
    IL_0022:  stloc.0
    IL_0023:  leave      IL_002d
    IL_0028:  leave      IL_002d
  }  // end handler
  IL_002d:  ldloc.0
  IL_002e:  newobj     instance void [scalalib]scala.runtime.NonLocalReturnControl::.ctor(object,
                                                                                          object)
  IL_0033:  throw
} // end of method $anonfun$main$1::apply

And the error message:

ABC$+$anonfun$main$1::apply][offset 0x00000008] Attempt to enter a try block with nonempty stack.

@scabug
Copy link
Author

scabug commented Jan 17, 2012

Hai Bison (haibison) said:
Thank you. However, I'll keep watching. I'm not meeting these knowledge...

@scabug
Copy link
Author

scabug commented Mar 3, 2012

@paulp said:
02e260a8e6

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

No branches or pull requests

1 participant