Skip to content

Commit

Permalink
Error on redefinition of Abstract Type (#25)
Browse files Browse the repository at this point in the history
* Error on redefinition of Abstract Type

* Update ProtoStruct.jl

* Update ProtoStructs.jl

* Update Project.toml

* Update ProtoStructs.jl

* Remove InteractiveUtils dependency

---------

Co-authored-by: Simon Christ <[email protected]>
  • Loading branch information
Tortar and BeastyBlacksmith authored Oct 16, 2023
1 parent 63c20c8 commit da2620e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ macro proto(expr)
properties::NT
end
else
if ($abstract_type != Any) && ($abstract_type != Base.supertype($name))
error("The supertype of a proto struct is not redefinable. Please restart your julia session.")
end
the_methods = collect(methods($name))
Base.delete_method(the_methods[1])
Base.delete_method(the_methods[2])
Expand Down Expand Up @@ -165,6 +168,9 @@ macro proto(expr)
properties::NT
end
else
if ($abstract_type != Any) && ($abstract_type != Base.supertype($name))
error("The supertype of a proto struct is not redefinable. Please restart your julia session.")
end
the_methods = collect(methods($name))
Base.delete_method(the_methods[1])
Base.delete_method(the_methods[2])
Expand Down
2 changes: 1 addition & 1 deletion src/ProtoStructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export @proto

include("ProtoStruct.jl")

end # module
end
7 changes: 7 additions & 0 deletions test/test_ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ end
tpm = @test_nowarn TestParametricMutation(D = 1, E = "yepp")
@test tpm isa TestParametricMutation{Int}
@test tpm isa AbstractMutation
@test_throws ErrorException @proto mutable struct TestParametricMutation{V<:Integer} <: Number
A::Int = 1
B = :no
C::Nothing = nothing
D::V
E::String
end
end

@static if VERSION >= v"1.8"
Expand Down

0 comments on commit da2620e

Please sign in to comment.