Repository: Roger-luo/Configurations.jl (julia)

Issue:
from_dict kwargs override too much
```julia
julia> using Configurations

julia> @option struct A
           x=1
           y=2
       end

julia> @option struct B
           a::A=A()
       end

julia> d = Dict(
       "a" => Dict("x" => 123),
       );

julia> Configurations.from_dict(B, d)
B(;
    a = A(;
        x = 123,
    ),
)

julia> Configurations.from_dict(B, d; a_y=999)
B(;
    a = A(        y = 999,
    ),
)
```

in the last result, I expected `x` to be set to `123`.

Pull request description:
this should fix #27 

I think @fonsp forget to change the test in #28  so that test fails, I somehow wrote the wrong unit test. I just copied your solution here.

Patch:
diff --git a/src/parse.jl b/src/parse.jl
index 0431e33..70751cb 100644
--- a/src/parse.jl
+++ b/src/parse.jl
@@ -27,7 +27,7 @@ OptionA(;
 function from_dict(::Type{T}, d::AbstractDict{String}; kw...) where T
     # override dict values
     validate_keywords(T; kw...)
-    from_kwargs!(d, T; kw...)
+    from_kwargs!(deepcopy(d), T; kw...)
     return from_dict_validate(T, d)
 end
 
@@ -211,6 +211,10 @@ function from_kwargs!(d::AbstractDict{String}, ::Type{T}, prefix::Maybe{Symbol}
 
         if is_option(type) || type isa Union
             field_d = OrderedDict{String, Any}()
+            if haskey(d, string(name)) && d[string(name)] isa AbstractDict
+                field_d = merge!(field_d, d[string(name)])
+            end
+
             from_kwargs!(field_d, type, key; kw...)
             if !isempty(field_d)
                 d[string(name)] = field_d


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 64e9cbe..7796351 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -178,8 +178,8 @@ end
 
     @test from_dict(OptionB, d; opt_name = "AAA") == OptionB(;
         opt = OptionA(;
-            name = "AAA",
-            int = 1,
+            name = "Roger",
+            int = 2,
         ),
         float = 0.33,
     )