Skip to content

Commit

Permalink
Merge pull request #2062 from Shopify/vs-use-singleton-method-to-test…
Browse files Browse the repository at this point in the history
…-method-names

Use singleton method to verify if method name is valid
  • Loading branch information
vinistock authored Oct 30, 2024
2 parents 68bfb68 + f6cc98f commit 883476c
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions lib/tapioca/helpers/rbi_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,7 @@ def as_non_nilable_type(type)

sig { params(name: String).returns(T::Boolean) }
def valid_method_name?(name)
# Special case: Prism supports parsing `def @foo; end`, but the Sorbet parser doesn't. This condition can go away
# once Sorbet is using Prism under the hood as it will no longer result in an RBI that Sorbet can't parse
return false if name.start_with?("@")

result = Prism.parse("def #{name}(a); end")
return false unless result.success?

# We don't consider `def foo.bar` as valid for generating RBIs since only `def self.bar` is supported
method_def = result.value.statements.body.first
receiver = method_def.receiver
!receiver || receiver.is_a?(Prism::SelfNode)
Prism.parse("def self.#{name}(a); end").success?
end

sig { params(name: String).returns(T::Boolean) }
Expand Down

0 comments on commit 883476c

Please sign in to comment.