10000 Debugging notes for required params after optional params error by ghiculescu · Pull Request #5403 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Debugging notes for required params after optional params error #5403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2022

Conversation

ghiculescu
Copy link
Contributor
@ghiculescu ghiculescu commented Mar 3, 2022

I spent a bunch of time today debugging an error I was seeing on a Rails 7 app, where we were getting this error and it was pointing here: https://github.com/rails/rails/blob/2459c20afb508c987347f52148210d874a9af4fa/activerecord/lib/active_record/persistence.rb#L405

Eventually, with the help of @jeffcarbs and @paracycle I tracked it down to a def self.update! in an Active Record model. This method had a sig { void } but it seems like for some reason the names matching still triggered this error.

I'm not sure how to fix that or if it's even a bug, but I thought some debugging notes might help the next person to come across it. If it is considered a bug, happy to provide more info to help with replication.

I spent a bunch of time today debugging an error I was seeing on a Rails 7 app, where we were getting this error and it was pointing here: https://github.com/rails/rails/blob/2459c20afb508c987347f52148210d874a9af4fa/activerecord/lib/active_record/persistence.rb#L405

Eventually, with the help of @jeffcarbs and @paracycle I tracked it down to a `def self.update!` in an Active Record model. This method had a `sig { void }` but it seems like for some reason the names matching still triggered this error.

I'm not sure how to fix that or if it's even a bug, but I thought some debugging notes might help the next person to come across it.
@ghiculescu ghiculescu requested a review from a team as a code owner March 3, 2022 00:21
@ghiculescu ghiculescu requested review from aprocter and removed request for a team March 3, 2022 00:21
Copy link
Collaborator
@jez jez left a comment

Choose a reason for hiding this comment

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

Thanks. Do you mind sharing a test case? Should we add your test case into the sorbet-runtime test suite?

@jez jez enabled auto-merge (squash) March 3, 2022 00:24
@ghiculescu
Copy link
Contributor Author

This passes statically but raises at runtime:

# typed: true
require "sorbet-runtime"

module A
  def foo(x = 1, y)
  end
end

class B
  extend T::Sig
  extend A

  sig { params(z: String).void }
  def self.foo(z)
  end
end

B.foo("hi")

As does this

# typed: true
require "sorbet-runtime"

class A
  def self.foo(x = 1, y)
  end
end

class B < A
  extend T::Sig

  sig { params(z: String).void }
  def self.foo(z)
  end
end

B.foo("hi")

Would you consider that a bug?

@jez jez merged commit 0bc4348 into sorbet:master Mar 3, 2022
@ghiculescu ghiculescu deleted the patch-3 branch March 3, 2022 03:29
@ghiculescu
Copy link
Contributor Author

@jez not sure if you saw ^ but let me know if you'd like me to add that to https://github.com/sorbet/sorbet/tree/master/gems/sorbet-runtime/test somewhere

@paracycle
Copy link
Collaborator

@ghiculescu I think this is the call that is ultimately causing that error.

In your first example, A#foo ends up being a super method of B.foo (due to extend A) and when Sorbet runtime tries to process the super method, it can't deal with the required params after optional params. Similarly, in the second example, A.foo is the super method of B.foo.

This is arguably a bug, as in, theoretically, it can be better handled by Sorbet runtime, wrt to super methods.

@ghiculescu
Copy link
Contributor Author

Yes, I think you're right. It sounds like maybe we want to add some more scenarios to this path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0