Skip to content

Commit

Permalink
Merge pull request #16129 from JuliaLang/jb/fix16023
Browse files Browse the repository at this point in the history
fix #16023, undef var error with local in statement position
  • Loading branch information
JeffBezanson committed May 2, 2016
2 parents 5ed7bb7 + 4ed8d78 commit 6bc704d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3052,12 +3052,17 @@ static Value *emit_condition(jl_value_t *cond, const std::string &msg, jl_codect

static void emit_stmtpos(jl_value_t *expr, jl_codectx_t *ctx)
{
if (jl_is_symbol(expr) || jl_is_slot(expr))
return; // value not used, no point in attempting codegen for it
if (jl_is_gensym(expr))
return; // value not used, no point in attempting codegen for it
if (jl_is_linenode(expr))
return;
if (jl_is_slot(expr)) {
size_t sl = jl_slot_number(expr) - 1;
jl_varinfo_t &vi = ctx->slots[sl];
if (vi.usedUndef)
(void)emit_expr(expr, ctx);
return;
}
if (jl_is_newvarnode(expr)) {
jl_value_t *var = jl_fieldref(expr, 0);
assert(jl_is_slot(var));
Expand Down
7 changes: 7 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3857,3 +3857,10 @@ type Issue8712; end
f16089(args...) = typeof(args)
g16089() = f16089(UInt8)
@test g16089() === Tuple{DataType}

# issue #16023
function f16023()
x
x = 1
end
@test_throws UndefVarError f16023()

0 comments on commit 6bc704d

Please sign in to comment.