Skip to content

Commit

Permalink
Ensure defaults eval is called in the proper module context.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Apr 2, 2024
1 parent 33c6187 commit 8fd48dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-02T12:44:18","documenter_version":"1.3.0"}}
{"documenter":{"julia_version":"1.10.2","generation_timestamp":"2024-04-02T12:58:13","documenter_version":"1.3.0"}}
18 changes: 9 additions & 9 deletions src/computations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
),
)

Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 8fd48dc

Please sign in to comment.