You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add types for ActiveSupport::Notifications but noticed that block arity isn't considered for overloaded methods, but it is for procs (as can be seen by hovering over subscribe in VS Code).
# uses first sig - correctreturn1=ActiveSupport::Notifications.subscribe("some_event.gem_name")do |_name,start,finish,_id,_payload|
putsfinish - startend# uses first sig - not correctreturn2=ActiveSupport::Notifications.subscribe("some_event.gem_name")do |event|
putsevent.durationend# uses third sig - correctcallback1=->(_name,start,finish,_id,_payload){putsfinish - start}return3=ActiveSupport::Notifications.subscribe("some_event.gem_name",callback1)# uses fourth sig - correctcallback2=->(event){putsevent.duration}return4=ActiveSupport::Notifications.subscribe("some_event.gem_name",callback2)
Observed output
# uses first sig - not correctreturn2=ActiveSupport::Notifications.subscribe("some_event.gem_name")do |event|
# event is typed as String from the first sig, but should be# ActiveSupport::Notifications::Event from the second sigputsevent.durationend
I can probably split the changes to overload resolution out into their own change, because inferring types for lambda return values causes a few thousand new type errors on Stripe's codebase and will need some time before we can fix them.
I'm trying to add types for
ActiveSupport::Notifications
but noticed that block arity isn't considered for overloaded methods, but it is for procs (as can be seen by hovering oversubscribe
in VS Code).Depending on the arity given to either the framework will either pass a single
ActiveSupport::Notifications::Event
object or five positional arguments.Input
Since overloads don't work on Sorbet.run, omitting the link.
test.rbi:
test.rb:
Observed output
Expected behavior
See above snippet comments.
EDIT: I understand support for overloaded methods is limited, but I didn't see this particular limitation mentioned on https://sorbet.org/docs/overloads#restrictions-on-overloaded-methods
The text was updated successfully, but these errors were encountered: