Skip to content

Commit

Permalink
error_parent_of_nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
orso82 committed Sep 24, 2024
1 parent c0c574d commit 859d540
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1278,13 +1278,15 @@ export top_dd
push!(document[:Base], :top_dd)

"""
parent(ids::Union{IDS,IDSvector}; IDS_is_absolute_top::Bool=true)
parent(@nospecialize(ids::Union{IDS,IDSvector}); IDS_is_absolute_top::Bool=false, error_parent_of_nothing::Bool=true)
Return parent IDS/IDSvector in the hierarchy
If `IDS_is_absolute_top=true` then returns `nothing` instead of dd()
If `error_parent_of_nothing=true` then asking `parent(nothing)` will just return nothing
"""
function Base.parent(@nospecialize(ids::Union{IDS,IDSvector}); IDS_is_absolute_top::Bool=false)
function Base.parent(@nospecialize(ids::Union{IDS,IDSvector}); IDS_is_absolute_top::Bool=false, error_parent_of_nothing::Bool=true)
parent_value = getfield(ids, :_parent).value
if IDS_is_absolute_top && typeof(parent_value) <: DD
return nothing
Expand All @@ -1293,6 +1295,14 @@ function Base.parent(@nospecialize(ids::Union{IDS,IDSvector}); IDS_is_absolute_t
end
end

function Base.parent(ids::Nothing; IDS_is_absolute_top::Bool=false, error_parent_of_nothing::Bool=true)
if error_parent_of_nothing
error("Asking parent of Nothing")
else
return nothing
end
end

export parent
push!(document[:Base], :parent)

Expand Down

0 comments on commit 859d540

Please sign in to comment.