Skip to content

Commit

Permalink
Fix single-term tuple bug in 1.10 (#52)
Browse files Browse the repository at this point in the history
Closes issue #51 (MWE below):

MWE:

```julia
julia> VERSION
v"1.10.0"

julia> using StableHashTraits; bytes2hex(stable_hash((; input_hash = "/n52cY4kWll77ptBTsaGPHZ674i+1IHbJ641JxJzBH0="); version=2))
"c331db74ec9c5f0734fc860a18d3bf6353516536697ef109a90329fca1cf69cc"
```

```julia
julia> VERSION
v"1.9.4"

julia> using StableHashTraits; bytes2hex(stable_hash((; input_hash = "/n52cY4kWll77ptBTsaGPHZ674i+1IHbJ641JxJzBH0="); version=2))
"f66d39a34e9102ef30c52e322c230e1457ad7802155aa895f907d70c6efec680"
```
  • Loading branch information
haberdashPI authored Feb 14, 2024
1 parent 3f2c4e4 commit 5a902f6
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StableHashTraits"
uuid = "c5dd0088-6c3f-4803-b00e-f31a60c170fa"
authors = ["Beacon Biosignals, Inc."]
version = "1.1.7"
version = "1.1.8"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
5 changes: 4 additions & 1 deletion src/StableNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ end
if parsed isa Parsed && parsed.name == :Head &&
endswith(parsed.args[1], "@NamedTuple")
symbols_and_types = split_symbol_and_type.(parsed.args[2].args)
symbol_tuple = join(":" .* filter(!isempty, first.(symbols_and_types)), ",")
symbols = filter(!isempty, first.(symbols_and_types))
symbol_tuple = join(":" .* symbols, ",")
# single term tuples need an extra ","
length(symbols) == 1 && (symbol_tuple *= ",")
types = map(t -> parse_walker(fn, t), last.(symbols_and_types))
types_tuple = join(types, ",")
prefix = replace(parsed.args[1], "@NamedTuple" => "")
Expand Down
1 change: 1 addition & 0 deletions test/references/ref24_1_crc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2385585186
1 change: 1 addition & 0 deletions test/references/ref24_1_sha1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9e014a820cb2e80b7df7200c7885623e54949ce1
1 change: 1 addition & 0 deletions test/references/ref24_1_sha256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dbe18ef31500a10398f1b322517303f504619b9b03c678a3d5eb63416b08cfa0
1 change: 1 addition & 0 deletions test/references/ref24_2_crc32c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1976339732
1 change: 1 addition & 0 deletions test/references/ref24_2_sha1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c5e6fbadb1446f6c2b7526741e660be98d94c7e4
1 change: 1 addition & 0 deletions test/references/ref24_2_sha256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f0dff5a41c275d19e385697d4e7e0713ad97dffe944ada9683ec2926b235bf39
1 change: 1 addition & 0 deletions test/references/ref25_1_crc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35764140
1 change: 1 addition & 0 deletions test/references/ref25_1_sha1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
055a2d716e034cbc4e1f4059e8fb268bf0799f7b
1 change: 1 addition & 0 deletions test/references/ref25_1_sha256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c2695992a0d887046f550cf667ba779953e4fba1403b2688e09087e5f3e8b0d9
1 change: 1 addition & 0 deletions test/references/ref25_2_crc32c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2321317094
1 change: 1 addition & 0 deletions test/references/ref25_2_sha1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f6c3803b31ce830da16459c12058a1c5f1a14325
1 change: 1 addition & 0 deletions test/references/ref25_2_sha256.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d0105644eda4819c4549da098c5332315323d6e52f140845dbb7a8f50286bccc
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ include("setup_tests.jl")
bytes2hex_(test_hash((;))))
@test_reference("references/ref23_$(V)_$(nameof(hashfn)).txt",
((; kwargs...) -> test_hash(kwargs))(; b=2, a=1))
@test_reference("references/ref24_$(V)_$(nameof(hashfn)).txt",
bytes2hex_(test_hash((; a=1))))
@test_reference("references/ref25_$(V)_$(nameof(hashfn)).txt",
bytes2hex_(test_hash((a=1, b=(;), c=(; c1=1),
d=(d1=1, d2=2)))))
end
# verifies that transform can be called recursively

Expand Down Expand Up @@ -402,6 +407,11 @@ include("setup_tests.jl")
@test cleanup_named_tuple_type(string(typeof((;)))) == "NamedTuple{(),Tuple{}}"
@test cleanup_named_tuple_type("@NamedTuple{x::Int, y::Int}") ==
"NamedTuple{(:x,:y),Tuple{Int,Int}}"
new_type_str = "@NamedTuple{a::Int64, b::@NamedTuple{}, c::@NamedTuple{c1::Int64}, d::@NamedTuple{d1::Int64, d2::Int64}}"
old_type_str = "NamedTuple{(:a,:b,:c,:d),Tuple{Int64,NamedTuple{(),Tuple{}},NamedTuple{(:c1,),Tuple{Int64}},NamedTuple{(:d1,:d2),Tuple{Int64,Int64}}}}"
@test cleanup_named_tuple_type(new_type_str) == old_type_str
@test cleanup_named_tuple_type("@NamedTuple{x::Int}") ==
"NamedTuple{(:x,),Tuple{Int}}"
@test cleanup_named_tuple_type("FooBar{Baz{Float64, (custom, display(}, " *
"@NamedTuple{x::Int, y::Int}}") ==
"FooBar{Baz{Float64, (custom, display(}, NamedTuple{(:x,:y),Tuple{Int,Int}}}"
Expand Down

2 comments on commit 5a902f6

@haberdashPI
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/100865

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.8 -m "<description of version>" 5a902f679678a4312dfed887f44d817a2174dde4
git push origin v1.1.8

Please sign in to comment.