From b3d467ca312ba04b35f3cd38e398d7821a023f6d Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 24 Nov 2014 23:10:09 -0500 Subject: [PATCH] fix #9134, regression on uninitialized `let` variable --- src/codegen.cpp | 3 +-- test/core.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index c208900b0bb31..8bb0d7eff0c02 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2620,8 +2620,7 @@ static Value *emit_var(jl_sym_t *sym, jl_value_t *ty, jl_codectx_t *ctx, bool is } assert(jbp == NULL); if (arg != NULL || // arguments are always defined - !vi.isAssigned || - (!is_var_closed(sym, ctx) && + ((!is_var_closed(sym, ctx) || !vi.isAssigned) && !jl_subtype((jl_value_t*)jl_undef_type, ty, 0))) { Value *theLoad = builder.CreateLoad(bp, vi.isVolatile); if (vi.closureidx > -1 && !(vi.isAssigned && vi.isCaptured)) diff --git a/test/core.jl b/test/core.jl index f1d7fe2550001..5320d08845608 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1953,3 +1953,12 @@ end end @test I8978.h(4) === 7.0 + +# issue #9134 +function f9134() + ii = zeros(Int32, 1) + let i + ii[1] = i + end +end +@test_throws UndefVarError f9134()