Skip to content

Commit

Permalink
Fix macro hygiene when calling the macro in the same module.
Browse files Browse the repository at this point in the history
Closes #14893
  • Loading branch information
yuyichao committed Jun 1, 2016
1 parent dd85275 commit e0d0a0b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ transpose(F::Factorization) = error("transpose not implemented for $(typeof(F))"
ctranspose(F::Factorization) = error("ctranspose not implemented for $(typeof(F))")

macro assertposdef(A, info)
:(($info)==0 ? $A : throw(PosDefException($info)))
:($(esc(info)) == 0 ? $(esc(A)) : throw(PosDefException($(esc(info)))))
end

macro assertnonsingular(A, info)
:(($info)==0 ? $A : throw(SingularException($info)))
:($(esc(info)) == 0 ? $(esc(A)) : throw(SingularException($(esc(info)))))
end


Expand Down
2 changes: 1 addition & 1 deletion base/sparse/cholmod_h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ type CHOLMODException <: Exception
end

macro isok(A)
:($A == TRUE || throw(CHOLMODException("")))
:($(esc(A)) == TRUE || throw(CHOLMODException("")))
end
2 changes: 1 addition & 1 deletion base/sparse/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function umferror(status::Integer)
end

macro isok(A)
:(umferror($A))
:(umferror($(esc(A))))
end

# check the size of SuiteSparse_long
Expand Down
16 changes: 8 additions & 8 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t narg
fl_gc_handle(fl_ctx, &scm);
value_t scmresult;
jl_module_t *defmod = mfunc->def->module;
if (defmod == NULL || defmod == jl_current_module) {
scmresult = fl_cons(fl_ctx, scm, fl_ctx->F);
}
else {
value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
*(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
scmresult = fl_cons(fl_ctx, scm, opaque);
}
/* if (defmod == NULL || defmod == jl_current_module) { */
/* scmresult = fl_cons(fl_ctx, scm, fl_ctx->F); */
/* } */
/* else { */
value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
*(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
scmresult = fl_cons(fl_ctx, scm, opaque);
/* } */
fl_free_gc_handles(fl_ctx, 1);

JL_GC_POP();
Expand Down
2 changes: 1 addition & 1 deletion src/macroexpand.scm
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
(error (cadr form)))
(let ((form (car form))
(m (cdr form)))
;; m is the macro's def module, or #f if def env === use env
;; m is the macro's def module
(rename-symbolic-labels
(julia-expand-macros
(resolve-expansion-vars form m))))))
Expand Down
21 changes: 20 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ end

# issue 13855
macro m13855()
Expr(:localize, :(() -> x))
Expr(:localize, :(() -> $(esc(:x))))
end
@noinline function foo13855(x)
@m13855()
Expand Down Expand Up @@ -4211,3 +4211,22 @@ global x
TestModuleAssignment.x = 1
@test x == 1
end

# issue #14893
module M14893
x = 14893
macro m14893()
:x
end
function f14893()
x = 1
@m14893
end
end
function f14893()
x = 2
M14893.@m14893
end

@test f14893() == 14893
@test M14893.f14893() == 14893

0 comments on commit e0d0a0b

Please sign in to comment.