Skip to content

Commit 98e7d26

Browse files
committed
Fix handling of empty array optional argument rb prototype
The rubyvm code only handled `LIST` but should have checked `ZLIST` as well. As such the type was untyped previously
1 parent fe9262e commit 98e7d26

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

lib/rbs/prototype/rb.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,7 @@ def param_type(node, default: Types::Bases::Any.new(location: nil))
838838
when Prism::TrueNode, Prism::FalseNode
839839
Types::Bases::Bool.new(location: nil)
840840
when Prism::ArrayNode
841-
# FIXME bug replicating empty array untyped
842-
if node.elements.any?
843-
BuiltinNames::Array.instance_type(default)
844-
else
845-
default
846-
end
841+
BuiltinNames::Array.instance_type(default)
847842
when Prism::HashNode
848843
BuiltinNames::Hash.instance_type(default, default)
849844
else

test/rbs/rb_prototype_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def self.world
4949
end
5050
5151
def kw_req(a:) end
52+
53+
def empty_array_opt(a = []) end
5254
end
5355
EOR
5456

@@ -59,6 +61,8 @@ def hello: (untyped a, ?::Integer b, *untyped c, untyped d, e: untyped, ?f: ::In
5961
def self.world: () { (untyped, untyped, untyped, x: untyped, y: untyped) -> untyped } -> untyped
6062
6163
def kw_req: (a: untyped) -> nil
64+
65+
def empty_array_opt: (?::Array[untyped] a) -> nil
6266
end
6367
EOF
6468
end

0 commit comments

Comments
 (0)