Skip to content

Commit 2fc1d8a

Browse files
committed
Support self in method
1 parent 42aeb20 commit 2fc1d8a

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/rbs/prototype/rb.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ def process(node, decls:, comments:, context:)
372372
end
373373

374374
value_node = node.children.last
375-
type = if value_node.nil?
376-
# Give up type prediction when node is MASGN.
375+
type = if value_node.nil? || value_node.type == :SELF
376+
# Give up type prediction when node is MASGN or SELF.
377377
Types::Bases::Any.new(location: nil)
378378
else
379379
literal_to_type(value_node)
@@ -671,7 +671,7 @@ def literal_to_type(node)
671671
BuiltinNames::Hash.instance_type(key_type, value_type)
672672
end
673673
when :SELF
674-
Types::Bases::Any.new(location: nil)
674+
Types::Bases::Self.new(location: nil)
675675
when :CALL
676676
receiver, method_name, * = node.children
677677
case method_name

test/rbs/rb_prototype_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def hash3: () -> { foo: { bar: 42 }, x: { y: untyped } }
174174
175175
def hash4: () -> ::Hash[:foo | untyped, 1 | untyped]
176176
177-
def self1: () -> untyped
177+
def self1: () -> self
178178
end
179179
EOF
180180
end

0 commit comments

Comments
 (0)