Skip to content

Commit

Permalink
add support for subtyping
Browse files Browse the repository at this point in the history
  • Loading branch information
SBuercklin committed May 8, 2023
1 parent b96fde2 commit 38dac15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/private_struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,9 @@ function find_private_fields(_ex)
return Tuple(private_fields), out_ex
end

function get_struct_info(_ex)
sname = MacroTools.postwalk(_ex) do ex
@capture(ex, (struct ((sname_{X__}) | (sname_))
fields__
end)) || return ex
return sname
end
return sname
function get_struct_info(ex)
sdef = MacroTools.splitstructdef(ex)
return sdef[:name]
end

function build_private_fields(struct_name, private_fields)
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ using Test, PrivateFields
const PF = PrivateFields

@testset "Private Definitions" begin
@private_struct struct Foo{X,Y}
# Test with <: Any to verify subtyping workings
@private_struct struct Foo{X,Y} <: Any
@private x::X
y::Y
end

@test PF.private_fieldnames(Foo) == (:x,)

@private_struct struct Bar
# Test with <: Any to verify subtyping workings
@private_struct struct Bar <: Any
x
@private y
z
Expand Down

2 comments on commit 38dac15

@SBuercklin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/83075

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 38dac1534227252fbd35271b95cac232349ff484
git push origin v0.1.0

Please sign in to comment.