tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

IdentityCache compiler generates wrong return types for `fetch_multi_n_by_m` fields

Open bitwise-aiden opened this issue 1 year ago • 1 comments

Description

After implementing the missing fetch_multi_n_by_m methods in https://github.com/Shopify/tapioca/pull/1758 I have found out that the method signature isn't always correct as shown in this example from cache_attribute: https://github.com/Shopify/identity_cache/blob/main/lib/identity_cache/cached/attribute.rb#L82-L101

The result of methods that include by in the name is a hash where:

  • Key: type m (be it a single value or an array of multiple)
  • Value: type n or T::Array[n] depending on things like if unique has been passed to cache_attribute.

So at present when the return type is T::Array[n], it would be expected that it is actually T::Hash[T.untyped, n] or T::Hash[T.untyped, T::Array[n]] based on how it was created.

bitwise-aiden avatar Jan 19 '24 23:01 bitwise-aiden

@KaanOzkan @Morriar So as not hold it up any further, I've marked two calls in the latest Core RBI update as T.unsafe, with smart TODOs pointing at this issue.

andyw8 avatar Jan 26 '24 20:01 andyw8