Roger-luo / Configurations.jl

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

is partial default value supported? #70

Closed johnnychen94 closed 2 years ago

johnnychen94 commented 2 years ago

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
Roger-luo commented 2 years ago

yeah this should be a bug