@variables as function parameter

Hi,
I started playing with the IntervalConstraintProgramming module in Julia, and ran into a problem.
Here is a minimal example:

using IntervalConstraintProgramming
using IntervalArithmetic
using ModelingToolkit

function test(X, vars)
	hc4 = Contractor(vars, x + y)
	return hc4(0..0, X)
end

vars = @variables x y
X = IntervalBox(0..5, 0..Inf)
new_X = test(X, vars)

and I get:

ERROR: MethodError: no method matching (::getfield(IntervalConstraintProgramming, Symbol("##53#54")))(::IntervalBox{2,Float64})
The applicable method may be too new: running in world age 25183, while current world is 25185.
Closest candidates are:
  #53(::Any) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/code_generation.jl:192 (method too new to be called from this world context.)
Stacktrace:
 [1] (::IntervalConstraintProgramming.GeneratedFunction{getfield(IntervalConstraintProgramming, Symbol("##53#54"))})(::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/code_generation.jl:12
 [2] contract(::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation}, ::IntervalBox{1,Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:54
 [3] (::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation})(::IntervalBox{1,Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:78
 [4] (::Contractor{2,1,getfield(IntervalConstraintProgramming, Symbol("##53#54")),getfield(IntervalConstraintProgramming, Symbol("##55#56")),Operation})(::Interval{Float64}, ::IntervalBox{2,Float64}) at /u/v/vanaret/.julia/packages/IntervalConstraintProgramming/MlctF/src/contractor.jl:82
 [5] test(::IntervalBox{2,Float64}, ::Tuple{Variable,Variable}) at ./REPL[36]:3
 [6] top-level scope at none:0

Does it have to do with the @variables passed as function parameter? The error mentions the code generation of the contractor, and my knowledge of Julia is too limited to understand.
Thanks for your help,

Charlie

This is a major issue in Julia when generating code and using @eval.
Basically you have to go back up to “top level” (outside any functions) before using functions that are defined like this.

You could rewrite your code like this:


julia> function make_contractor(vars)
               hc4 = Contractor(vars, x + y)
               return hc4
       end
test (generic function with 2 methods)

julia> hc4 = make_contractor(vars);

julia> function run_contractor(C, X)
           return C(0..0, X)
       end

julia> run_contractor(hc4, X)
[0, 0] × [0, 0]