Skip to content

Commit

Permalink
Allow kwdef macro outside of definition of struct (#18)
Browse files Browse the repository at this point in the history
* Allow kwdef macro outside of definition of struct

* Update test_ProtoStruct.jl

* better matching

* Update ProtoStruct.jl

* Update ProtoStruct.jl

---------

Co-authored-by: Simon Christ <[email protected]>
  • Loading branch information
Tortar and BeastyBlacksmith authored Oct 13, 2023
1 parent 77ed9ed commit 32acc26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ProtoStruct.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
macro proto( expr )
if expr.head == :macrocall && expr.args[1] == Symbol("@kwdef")
expr = expr.args[3]
end

if expr.head != Symbol("struct")
throw(ArgumentError("Expected expression to be a type definition."))
end
Expand Down
10 changes: 10 additions & 0 deletions test/test_ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ end
@test tw.E == "yepp"
end

@proto @kwdef struct TestMacroOutside
A::Int = 1
end

@testset "@kwdef macro outside" begin
tw = TestMacroOutside()
@test tw isa TestMacroOutside
@test tw.A == 1
end

@proto mutable struct TestMutation
F::Int
G::Float64
Expand Down

0 comments on commit 32acc26

Please sign in to comment.