10000 Implement context validation on parse by ksss · Pull Request #2336 · ruby/rbs · GitHub
[go: up one dir, main page]

Skip to content

Implement context validation on parse #2336

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Support self in method
  • Loading branch information
ksss committed May 27, 2025
commit 55640d173e180738175bd3bb1cf0af91726e6e2c
6 changes: 3 additions & 3 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def process(node, decls:, comments:, context:)
end

value_node = node.children.last
type = if value_node.nil?
# Give up type prediction when node is MASGN.
type = if value_node.nil? || value_node.type == :SELF
# Give up type prediction when node is MASGN or SELF.
Types::Bases::Any.new(location: nil)
else
literal_to_type(value_node)
Expand Down Expand Up @@ -671,7 +671,7 @@ def literal_to_type(node)
BuiltinNames::Hash.instance_type(key_type, value_type)
end
when :SELF
Types::Bases::Any.new(location: nil)
Types::Bases::Self.new(location: nil)
when :CALL
receiver, method_name, * = node.children
case method_name
Expand Down
2 changes: 1 addition & 1 deletion test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def hash3: () -> { foo: { bar: 42 }, x: { y: untyped } }

def hash4: () -> ::Hash[:foo | untyped, 1 | untyped]

def self1: () -> untyped
def self1: () -> self
end
EOF
end
Expand Down
0