From 8fd48dcec6ca4f701c7c487bd95d80cb49330b84 Mon Sep 17 00:00:00 2001 From: Oren Ben-Kiki Date: Tue, 2 Apr 2024 12:59:21 +0300 Subject: [PATCH] Ensure defaults eval is called in the proper module context. --- docs/v0.1.0/.documenter-siteinfo.json | 2 +- src/computations.jl | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/v0.1.0/.documenter-siteinfo.json b/docs/v0.1.0/.documenter-siteinfo.json index f9d988a..44f56e7 100644 --- a/docs/v0.1.0/.documenter-siteinfo.json +++ b/docs/v0.1.0/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-02T12:44:18","documenter_version":"1.3.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-02T12:58:13","documenter_version":"1.3.0"}} \ No newline at end of file diff --git a/src/computations.jl b/src/computations.jl index 11363ac..1aca14a 100644 --- a/src/computations.jl +++ b/src/computations.jl @@ -123,7 +123,7 @@ macro computation(definition) set_metadata_of_function( function_module, function_name, - FunctionMetadata(Contract[], collect_defaults(inner_definition)), + FunctionMetadata(Contract[], collect_defaults(function_module, inner_definition)), ) inner_definition[:name] = Symbol(function_name, :_inner) @@ -152,7 +152,7 @@ macro computation(contract, definition) set_metadata_of_function( function_module, function_name, - FunctionMetadata([function_module.eval(contract)], collect_defaults(inner_definition)), + FunctionMetadata([function_module.eval(contract)], collect_defaults(function_module, inner_definition)), ) inner_definition[:name] = Symbol(function_name, :_inner) @@ -187,7 +187,7 @@ macro computation(first_contract, second_contract, definition) function_name, FunctionMetadata( [function_module.eval(first_contract), function_module.eval(second_contract)], - collect_defaults(inner_definition), + collect_defaults(function_module, inner_definition), ), ) @@ -240,22 +240,22 @@ function patch_kwarg(arg::Expr)::Any return arg end -function collect_defaults(inner_definition)::Dict{AbstractString, Any} +function collect_defaults(function_module::Module, inner_definition)::Dict{AbstractString, Any} defaults = Dict{AbstractString, Any}() for arg in get(inner_definition, :args, []) - collect_arg_default(defaults, arg) + collect_arg_default(function_module, defaults, arg) end for kwarg in get(inner_definition, :kwargs, []) - collect_arg_default(defaults, kwarg) + collect_arg_default(function_module, defaults, kwarg) end return defaults end -function collect_arg_default(defaults::Dict{AbstractString, Any}, arg::Symbol)::Nothing # untested +function collect_arg_default(function_module::Module, defaults::Dict{AbstractString, Any}, arg::Symbol)::Nothing # untested return nothing end -function collect_arg_default(defaults::Dict{AbstractString, Any}, arg::Expr)::Nothing +function collect_arg_default(function_module::Module, defaults::Dict{AbstractString, Any}, arg::Expr)::Nothing if arg.head == :kw @assert length(arg.args) == 2 name = arg.args[1] @@ -265,7 +265,7 @@ function collect_arg_default(defaults::Dict{AbstractString, Any}, arg::Expr)::No @assert length(name.args) == 2 name = name.args[1] end - defaults[string(name)] = eval(value) + defaults[string(name)] = function_module.eval(value) end return nothing end