Skip to content

Commit ba065de

Browse files
authored
Index NamedTuples with StaticSymbol (Fix #120) (#121)
Index NamedTuples with StaticSymbol (Fix #120)
1 parent 7206760 commit ba065de

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Static"
22
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
33
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
4-
version = "0.8.8"
4+
version = "0.8.9"
55

66
[deps]
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/Static.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Base.promote_rule(::Type{Bool}, T::Type{<:StaticNumber}) = promote_rule(Bool, el
8181

8282
Base.getindex(x::Tuple, ::StaticInt{N}) where {N} = getfield(x, N)
8383

84+
Base.getindex(x::NamedTuple, ::StaticSymbol{N}) where {N} = getfield(x, N)
85+
8486
Base.zero(@nospecialize(::StaticInt)) = StaticInt{0}()
8587

8688
Base.to_index(x::StaticInt) = known(x)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Aqua.test_all(Static, piracy = false)
1515
@test @inferred(StaticSymbol(x, y)) === StaticSymbol(:x, :y)
1616
@test @inferred(StaticSymbol(x, y, z)) === static(:xy1)
1717
@test @inferred(static(nothing)) === nothing
18+
nt = (x = :x, y = "y", z = 1)
19+
@test @inferred(getindex(nt, x)) == :x
1820
@test_throws ErrorException static([])
1921
end
2022

0 commit comments

Comments
 (0)