validate state in FrameMap.leave

fix variable leave order
This commit is contained in:
Stepan Koltsov
2012-06-05 22:56:23 +04:00
parent cf9dec51f5
commit fbdfd5a5fb
2 changed files with 7 additions and 2 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.jet.codegen;
import com.google.common.collect.Lists;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiElement;
@@ -875,7 +876,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
Label blockEnd = new Label();
v.mark(blockEnd);
for (JetElement statement : statements) {
for (JetElement statement : Lists.reverse(statements)) {
if(statement instanceof JetNamedFunction) {
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, statement);
myFrameMap.leave(descriptor);
@@ -41,7 +41,11 @@ public class FrameMap {
int size = myVarSizes.get(descriptor);
myMaxIndex -= size;
myVarSizes.remove(descriptor);
return myVarIndex.remove(descriptor);
int oldIndex = myVarIndex.remove(descriptor);
if (oldIndex != myMaxIndex) {
throw new IllegalStateException("descriptor can be left only if it is last");
}
return oldIndex;
}
public int enterTemp() {