Mutation methods type-locking question
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 256
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 37
Description
We (at Datadog) stumble upon situation when we use Hash#transform_values! and we get into the trap of type-locking introduced in this PR https://github.com/ruby/rbs/pull/728
What do you think of making both mutation methods have the same signature, like this one (taken from the original transform_values)?
def transform_values: () -> Enumerator[V, Hash[K, untyped]]
| [A] () { (V) -> A } -> Hash[K, A]
Because now there is no way to change the type of say, this expression (response is Net::HTTPResponse)
response.to_hash.transform_values! { |value| Array(value).join }
when run Steep it will complain that original Hash typed as Hash[String, Array[String]] and if something expects to get Hash[String, String] the check will fail, but in fact we mutate the value to be a String.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Hash#transform_values! signature described in this issue and compare it with the original transform_values signature from ruby/rbs#728. Reproduce the Net::HTTPResponse example with Steep and check whether the mutation can change Hash[String, Array[String]] to Hash[String, String] without a type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100