Thank you for looking into it!
No, unfortunately (or fortunately?), it doesn't work. That was actually the thing that really confused me. I knew that adding classes (which present in official documentation). But it also didn't work but was never digging into details.
But turned, that adding value without modification never works for value types due to modify never called, i.e.:
let value = dict[1, default: "test"].count // or whatever non-mutating method is used
print(value) // prints `4`
print(dict) // prints `[:]`
I would say it is not intuitive and rather error prone. But now I think that maybe I should've put that in documentation section to add this note to the official docc here (same as for class): subscript(_:default:) | Apple Developer Documentation
Yeah, I would also not be much concerned about integers or other basic primitives.
And I see a solution from @lukasa to avoid hash re-calculation in other thread:
So, if I ever have the problem in hashing at this path I know what to do, so can put it to some helpers.
But I would vote to have this function in stdlib!