From 6f5657c35d59a8d1dcf78402f710a55fa77c4e02 Mon Sep 17 00:00:00 2001 From: Juan Wajnerman <jwajnerman@manas.com.ar> Date: Tue, 21 Jan 2014 19:36:49 -0300 Subject: [PATCH] Save/restore exception handlers while generating consts --- spec/compiler/codegen/const_spec.cr | 14 ++++++++++++++ src/compiler/crystal/codegen.cr | 3 +++ 2 files changed, 17 insertions(+) diff --git a/spec/compiler/codegen/const_spec.cr b/spec/compiler/codegen/const_spec.cr index c524f4039a..7e3d477e68 100644 --- a/spec/compiler/codegen/const_spec.cr +++ b/spec/compiler/codegen/const_spec.cr @@ -136,4 +136,18 @@ describe "Codegen: const" do Foo.new.compile ").to_i.should eq(1) end + + it "initialize const that might raise an exception" do + run(" + require \"prelude\" + CONST = (raise \"OH NO\" if 1 == 2) + + def doit + CONST + rescue + end + + doit.nil? + ").to_b.should be_true + end end diff --git a/src/compiler/crystal/codegen.cr b/src/compiler/crystal/codegen.cr index 9a0c569504..2da119f122 100644 --- a/src/compiler/crystal/codegen.cr +++ b/src/compiler/crystal/codegen.cr @@ -2451,6 +2451,8 @@ module Crystal old_fun = @fun old_in_const_block = @in_const_block old_llvm_mod = @llvm_mod + old_exception_handlers = @exception_handlers + @exception_handlers = [] of Handler @in_const_block = true @llvm_mod = @main_mod @@ -2469,6 +2471,7 @@ module Crystal @fun = old_fun @llvm_mod = old_llvm_mod @in_const_block = old_in_const_block + @exception_handlers = old_exception_handlers end def printf(format, args = [] of LibLLVM::ValueRef) -- GitLab