Roger-luo / Configurations.jl

Options & Configurations made easy.
https://configurations.rogerluo.dev/stable
MIT License
80 stars 12 forks source link

BUG: Cannot use another field as a fallback value #103

Open schlichtanders opened 6 months ago

schlichtanders commented 6 months ago

I am unable to create a config like

using Configurations
@option struct MyConfig
    a = 3
    b = a
end

it will fail with an error similar to the following

Failed to precompile MyPackage [02ff3102-a342-4357-ad22-369f4532ef5a] to "/home/myhome/.julia/compiled/v1.10/MyPackage/jl_Zquwz2".
ERROR: LoadError: MethodError: no method matching maybe_wrap_block(::Symbol)

Closest candidates are:
  maybe_wrap_block(::Expr)
   @ ExproniconLite ~/.julia/packages/ExproniconLite/rSIkX/src/codegen.jl:85

Stacktrace:
 [1] codegen_ast(fn::ExproniconLite.JLFunction)
   @ ExproniconLite ~/.julia/packages/ExproniconLite/rSIkX/src/codegen.jl:70
 [2] codegen_field_default(def::ExproniconLite.JLKwStruct)
   @ Configurations ~/.julia/packages/Configurations/Yxczn/src/codegen.jl:288
 [3] codegen_option_type(mod::Module, def::ExproniconLite.JLKwStruct)
   @ Configurations ~/.julia/packages/Configurations/Yxczn/src/codegen.jl:120
 [4] option_m(mod::Module, ex::Expr, type_alias::Nothing)
   @ Configurations ~/.julia/packages/Configurations/Yxczn/src/codegen.jl:89
 [5] option_m(mod::Module, ex::Expr)
   @ Configurations ~/.julia/packages/Configurations/Yxczn/src/codegen.jl:87
 [6] var"@option"(__source__::LineNumberNode, __module__::Module, ex::Any)
   @ Configurations ~/.julia/packages/Configurations/Yxczn/src/codegen.jl:79
 [7] include
   @ ./Base.jl:495 [inlined]
 [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing)
   @ Base ./loading.jl:2222
 [9] top-level scope
   @ stdin:3

A workaround is to use identity function as a pseudo wrapper

using Configurations
@option struct MyConfig
    a = 3
    b = identity(a)
end