Roger-luo / Configurations.jl

Options & Configurations made easy.

Home Page:https://configurations.rogerluo.dev/stable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is partial default value supported?

johnnychen94 opened this issue · comments

I'm not sure if this is a bug or intentionally not supported:

@option struct MyOption
    x::Int
    y::Int = x + 1
end
julia> from_dict(MyOption, Dict("x"=>1))
ERROR: MethodError: Cannot `convert` an object of type Configurations.PartialDefault{var"#5#7"} to an object of type Int64
Closest candidates are:
  convert(::Type{T}, ::Ptr) where T<:Integer at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/pointer.jl:23
  convert(::Type{T}, ::T) where T<:Number at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/number.jl:7
  ...
Stacktrace:
 [1] MyOption(x::Int64, y::Configurations.PartialDefault{var"#5#7"})
   @ Main ./REPL[4]:2
 [2] macro expansion
   @ ./dict.jl:0 [inlined]
 [3] from_dict_specialize(#unused#::Type{MyOption}, d::Dict{String, Int64})
   @ Main ~/.julia/packages/Configurations/ZUY5q/src/codegen.jl:315

yeah this should be a bug