Just ran into an issue in the DiffEq-sphere that seems like it might be a more systemic problem. I am wondering if there is a proper way to address it, or if this needs to be addressed in Julia itself. The issue is here:
https://github.com/JuliaDiffEq/StochasticDiffEq.jl/issues/16#issuecomment-286812619
but the problem is summed up as this. To define a type, I am using Parameters.jl. For example:
@with_kw immutable EM{RSType} <: StochasticDiffEqAlgorithm
rswm::RSType = RSWM(adaptivealg=:RSwM1)
end
the @with_kw
makes the constructor have a keyword argument as you’d expect from this definition, and all is well. However, last night a release was put in to Parameters.jl which updated it to use v0.6. Now, users suddenly get an error:
ERROR: LoadError: LoadError: UndefVarError: @compat not defined
in macro expansion; at ./none:2 [inlined]
in anonymous at ./<missing>:?
while loading /home/blegat/.julia/v0.5/StochasticDiffEq/src/algorithms.jl, in expression starting on line 5
while loading /home/blegat/.julia/v0.5/StochasticDiffEq/src/StochasticDiffEq.jl, in expression starting on line 21
ERROR: Failed to precompile StochasticDiffEq to /home/blegat/.julia/lib/v0.5/StochasticDiffEq.ji.
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
That means that Compat
isn’t in the modules scope. But it was added to Parameters.jl’s module scope in the recent change. The issue is that the requirement for the dependency leaked out:
The @with_kw
macro now puts in an @compat
. So when that expands, it ends up with an expression which has @compat
in it. So it seems that StochasticDiffEq.jl now needs a requirement and needs to pull @compat
into its scope.
Someone probably has a good minimum example for this, I’m mostly frantically trying to fix this right now. I am sure that it’s a leaking of the Compat dependency since I added using Compat
to StochasticDiffEq.jl master, but also I can fix release’s “you need Compat” bug by pinning Parameters.jl to v0.6.0.
Is there a way that we should be using nested macros to avoid this problem? Or should Julia be using the scope of where the macro was defined to handle nested macros?