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

Issue:
@static if inside @option
While trying to port Pluto to Configurations.jl, I found this:
```julia
julia> using Configurations

julia> f() = 123
f (generic function with 1 method)

julia> @option struct A
           x=f()
       end

julia> @option struct B
           x=1
           @static if true
               y=f()
           end
       end

julia> A()
A(;
)

julia> A(1)
A(;
    x = 1,
)

julia> B()
ERROR: MethodError: no method matching B(::Int64)
Closest candidates are:
  B(; x) at none:0
Stacktrace:
 [1] B(; x::Int64)
   @ Main ./none:0
 [2] B()
   @ Main ./none:0
 [3] top-level scope
   @ REPL[9]:1

julia> B(1,2)
ERROR: MethodError: no method matching B(::Int64, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

```

We use `@static` here: https://github.com/fonsp/Pluto.jl/blob/main/src/Configuration.jl#L84

Pull request description:
fix #39  need Expronicon 0.6.6

Patch:
diff --git a/src/codegen.jl b/src/codegen.jl
index cf768b3..98bcb64 100644
--- a/src/codegen.jl
+++ b/src/codegen.jl
@@ -71,14 +71,15 @@ OptionD(;
 ```
 """
 macro option(ex)
-    esc(option_m(ex))
+    esc(option_m(__module__, ex))
 end
 
 macro option(alias::String, ex)
-    esc(option_m(ex, alias))
+    esc(option_m(__module__, ex, alias))
 end
 
-function option_m(ex, type_alias=nothing)
+function option_m(mod::Module, ex, type_alias=nothing)
+    ex = macroexpand(mod, ex)
     def = JLKwStruct(ex, type_alias)
     return codegen_option_type(def)
 end


Test patch:
diff --git a/test/runtests.jl b/test/runtests.jl
index 65cb4e1..6071832 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -405,6 +405,17 @@ end
     @test from_dict(UnionToDict, d) == x
 end
 
+@option struct MacroExpand
+    x=1
+    @static if true
+        y=2
+    end
+end
+
+@testset "macroexpand (#39)" begin
+    @test fieldnames(MacroExpand) == (:x, :y)
+end
+
 @option struct DefaultFunction
     a::Float64
     b::Float64 = sin(a)