diff --git a/Project.toml b/Project.toml index 20a95ed..1ade710 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,11 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.7.2" +version = "0.8.0" [deps] ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +LightBoundsErrors = "e21c612c-4641-4669-b9c3-3f4360ced9da" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [weakdeps] @@ -31,6 +32,7 @@ Documenter = "1" GPUArraysCore = "0.2" InfiniteArrays = "0.15" JLArrays = "0.2" +LightBoundsErrors = "1" LinearAlgebra = "1" KernelAbstractions = "0.9" OffsetArrays = "1" diff --git a/src/StructArrays.jl b/src/StructArrays.jl index bef1167..6262df4 100644 --- a/src/StructArrays.jl +++ b/src/StructArrays.jl @@ -17,6 +17,8 @@ include("lazy.jl") include("constructionbase.jl") include("tables.jl") +using LightBoundsErrors: checkbounds_lightboundserror + # Implement refarray and refvalue to deal with pooled arrays and weakrefstrings effectively import DataAPI: refarray, refvalue using DataAPI: defaultarray diff --git a/src/structarray.jl b/src/structarray.jl index 24ab0fb..b3d4c8c 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -342,6 +342,10 @@ map(c -> c[I...], Tuple(cols)) """ @inline @generated get_ith(cols::Tup, I...) = :(Base.Cartesian.@ntuple $(fieldcount(cols)) i -> @inbounds cols[i][I...]) +function Base.checkbounds(x::StructArray, I...) + checkbounds_lightboundserror(x, I...) +end + Base.@propagate_inbounds Base.getindex(x::StructArray, I...) = _getindex(x, to_indices(x, I)...) Base.@propagate_inbounds function _getindex(x::StructArray{T}, I::Vararg{Int}) where {T} diff --git a/test/runtests.jl b/test/runtests.jl index 4484283..99a61cc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,7 @@ using LinearAlgebra using Test using SparseArrays using InfiniteArrays +using LightBoundsErrors: LightBoundsError import Aqua import KernelAbstractions as KA @@ -43,7 +44,7 @@ Base.convert(::Type{Millimeters}, x::Meters) = Millimeters(x.x*1000) t = StructArray((a = a, b = b)) @test (@inferred t[2,2]) == (a = 4, b = 7) @test (@inferred t[2,1:2]) == StructArray((a = [3, 4], b = [6, 7])) - @test_throws BoundsError t[3,3] + @test_throws LightBoundsError t[3,3] @test (@inferred view(t, 2, 1:2)) == StructArray((a = view(a, 2, 1:2), b = view(b, 2, 1:2))) @test @inferred(parentindices(view(t, 2, 1:2))) == (2, 1:2) @test_throws ArgumentError parentindices(StructArray((view([1, 2], [1]), view([1, 2], [2]))))