Skip to content

Commit 76a9183

Browse files
committed
added correct implementation of getrange for TypedVarInfo
1 parent fefebc2 commit 76a9183

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/varinfo.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,21 @@ getidx(md::Metadata, vn::VarName) = md.idcs[vn]
610610
Return the index range of `vn` in the metadata of `vi`.
611611
"""
612612
getrange(vi::VarInfo, vn::VarName) = getrange(getmetadata(vi, vn), vn)
613+
# For `TypedVarInfo` it's more difficult since we need to keep track of the offset.
614+
# TOOD: Should we unroll this using `@generated`?
615+
function getrange(vi::TypedVarInfo, vn::VarName)
616+
offset = 0
617+
for md in values(vi.metadata)
618+
# First, we need to check if `vn` is in `md`.
619+
# In this case, we can just return the corresponding range + offset.
620+
haskey(md, vn) && return getrange(md, vn) .+ offset
621+
# Otherwise, we need to get the cumulative length of the ranges in `md`
622+
# and add it to the offset.
623+
offset += sum(length, md.ranges)
624+
end
625+
# If we reach this point, `vn` is not in `vi.metadata`.
626+
throw(KeyError(vn))
627+
end
613628
getrange(md::Metadata, vn::VarName) = md.ranges[getidx(md, vn)]
614629

615630
"""

0 commit comments

Comments
 (0)