Skip to content

Commit e0d0a0b

Browse files
committed
Fix macro hygiene when calling the macro in the same module.
Closes #14893
1 parent dd85275 commit e0d0a0b

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

base/linalg/factorization.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ transpose(F::Factorization) = error("transpose not implemented for $(typeof(F))"
99
ctranspose(F::Factorization) = error("ctranspose not implemented for $(typeof(F))")
1010

1111
macro assertposdef(A, info)
12-
:(($info)==0 ? $A : throw(PosDefException($info)))
12+
:($(esc(info)) == 0 ? $(esc(A)) : throw(PosDefException($(esc(info)))))
1313
end
1414

1515
macro assertnonsingular(A, info)
16-
:(($info)==0 ? $A : throw(SingularException($info)))
16+
:($(esc(info)) == 0 ? $(esc(A)) : throw(SingularException($(esc(info)))))
1717
end
1818

1919

base/sparse/cholmod_h.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ type CHOLMODException <: Exception
7575
end
7676

7777
macro isok(A)
78-
:($A == TRUE || throw(CHOLMODException("")))
78+
:($(esc(A)) == TRUE || throw(CHOLMODException("")))
7979
end

base/sparse/umfpack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function umferror(status::Integer)
5454
end
5555

5656
macro isok(A)
57-
:(umferror($A))
57+
:(umferror($(esc(A))))
5858
end
5959

6060
# check the size of SuiteSparse_long

src/ast.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ value_t fl_invoke_julia_macro(fl_context_t *fl_ctx, value_t *args, uint32_t narg
172172
fl_gc_handle(fl_ctx, &scm);
173173
value_t scmresult;
174174
jl_module_t *defmod = mfunc->def->module;
175-
if (defmod == NULL || defmod == jl_current_module) {
176-
scmresult = fl_cons(fl_ctx, scm, fl_ctx->F);
177-
}
178-
else {
179-
value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
180-
*(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
181-
scmresult = fl_cons(fl_ctx, scm, opaque);
182-
}
175+
/* if (defmod == NULL || defmod == jl_current_module) { */
176+
/* scmresult = fl_cons(fl_ctx, scm, fl_ctx->F); */
177+
/* } */
178+
/* else { */
179+
value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*));
180+
*(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = (jl_value_t*)defmod;
181+
scmresult = fl_cons(fl_ctx, scm, opaque);
182+
/* } */
183183
fl_free_gc_handles(fl_ctx, 1);
184184

185185
JL_GC_POP();

src/macroexpand.scm

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
(error (cadr form)))
424424
(let ((form (car form))
425425
(m (cdr form)))
426-
;; m is the macro's def module, or #f if def env === use env
426+
;; m is the macro's def module
427427
(rename-symbolic-labels
428428
(julia-expand-macros
429429
(resolve-expansion-vars form m))))))

test/core.jl

+20-1
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,7 @@ end
33983398

33993399
# issue 13855
34003400
macro m13855()
3401-
Expr(:localize, :(() -> x))
3401+
Expr(:localize, :(() -> $(esc(:x))))
34023402
end
34033403
@noinline function foo13855(x)
34043404
@m13855()
@@ -4211,3 +4211,22 @@ global x
42114211
TestModuleAssignment.x = 1
42124212
@test x == 1
42134213
end
4214+
4215+
# issue #14893
4216+
module M14893
4217+
x = 14893
4218+
macro m14893()
4219+
:x
4220+
end
4221+
function f14893()
4222+
x = 1
4223+
@m14893
4224+
end
4225+
end
4226+
function f14893()
4227+
x = 2
4228+
M14893.@m14893
4229+
end
4230+
4231+
@test f14893() == 14893
4232+
@test M14893.f14893() == 14893

0 commit comments

Comments
 (0)