Skip to content

Commit 4162fa7

Browse files
authored
Merge pull request #1 from blegat/macro-hygiene
Fix @PolyVar macro when package is `import`ed
2 parents dbf3a3a + 3f2dab8 commit 4162fa7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/mono.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ end
1111

1212
function buildpolyvar(var)
1313
if isa(var, Symbol)
14-
esc(:($var = PolyVar($"$var")))
14+
:($(esc(var)) = PolyVar($"$var"))
1515
else
1616
isa(var, Expr) || error("Expected $var to be a variable name")
1717
Base.Meta.isexpr(var, :ref) || error("Expected $var to be of the form varname[idxset]")
@@ -20,7 +20,7 @@ function buildpolyvar(var)
2020
varname = var.args[1]
2121
prefix = string(var.args[1])
2222
idxset = var.args[2]
23-
esc(:($varname = polyvecvar($prefix, $idxset)))
23+
:($(esc(varname)) = polyvecvar($prefix, $idxset))
2424
end
2525
end
2626

test/mono.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ facts("Vector to Monomial Vector") do
1515
@fact MonomialVector([1]) --> MonomialVector(PolyVar[], [Int[]])
1616
@fact MonomialVector([x]) --> MonomialVector([x], [[1]])
1717
end
18+
module newmodule
19+
using FactCheck
20+
import MultivariatePolynomials
21+
facts("Polyvar macro hygiene") do
22+
# Verify that the @polyvar macro works when the package has been activated
23+
# with `import` instead of `using`.
24+
MultivariatePolynomials.@polyvar x y
25+
@fact isa(x, MultivariatePolynomials.PolyVar) --> true
26+
@fact isa(y, MultivariatePolynomials.PolyVar) --> true
27+
end
28+
end

0 commit comments

Comments
 (0)