From 57f14277dad0427b90abc1e6f70e2f8ae4dcbb51 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Thu, 7 Jan 2010 11:00:20 +0000 Subject: Fixed #2850 -- while inside finally causes Veri... Fixed #2850 -- while inside finally causes VerifyError, review by rytz --- src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 4e6507f9e3..cd690097e8 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1621,8 +1621,9 @@ abstract class GenICode extends SubComponent { override def equals(other: Any) = f == other; } - def duplicateFinalizer(ctx: Context, finalizer: Tree) = - (new DuplicateLabels(ctx.labels.keySet))(ctx, finalizer) + def duplicateFinalizer(boundLabels: collection.Set[Symbol], targetCtx: Context, finalizer: Tree) = { + (new DuplicateLabels(boundLabels))(targetCtx, finalizer) + } /** * The Context class keeps information relative to the current state @@ -1863,6 +1864,10 @@ abstract class GenICode extends SubComponent { var tmp: Local = null val kind = toTypeKind(tree.tpe) val guardResult = kind != UNIT && mayCleanStack(finalizer) + // we need to save bound labels before any code generation is performed on + // the current context (otherwise, any new lables in the finalizer that need to + // be duplicated would be incorrectly considered bound -- see #2850). + val boundLabels: collection.Set[Symbol] = Set.empty ++ labels.keySet if (guardResult) { tmp = this.makeLocal(tree.pos, tree.tpe, "tmp") @@ -1875,11 +1880,11 @@ abstract class GenICode extends SubComponent { if (guardResult) { ctx1.bb.emit(STORE_LOCAL(tmp)) - val ctx2 = genLoad(duplicateFinalizer(ctx1, finalizer), ctx1, UNIT) + val ctx2 = genLoad(duplicateFinalizer(boundLabels, ctx1, finalizer), ctx1, UNIT) ctx2.bb.emit(LOAD_LOCAL(tmp)) ctx2 } else - genLoad(duplicateFinalizer(ctx1, finalizer), ctx1, UNIT) + genLoad(duplicateFinalizer(boundLabels, ctx1, finalizer), ctx1, UNIT) } else ctx -- cgit v1.2.3