Skip to content

Commit

Permalink
Add length check guards for delete methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav-arya committed Jan 2, 2024
1 parent 019687e commit 29be0e5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ macro proto(expr)
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])
if length(the_methods) >= 1
Base.delete_method(the_methods[1])
end
if length(the_methods) >= 2
Base.delete_method(the_methods[2])
end
end

function $name($(fields...)) where {$(type_parameters...)}
Expand Down Expand Up @@ -181,8 +185,12 @@ macro proto(expr)
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])
if length(the_methods) >= 1
Base.delete_method(the_methods[1])
end
if length(the_methods) >= 2
Base.delete_method(the_methods[2])
end
end

function $name($(fields...)) where {$(type_parameters...)}
Expand Down

0 comments on commit 29be0e5

Please sign in to comment.