Skip to content

Commit

Permalink
Move the logic for CALL cases from node_type to literal_to_type.
Browse files Browse the repository at this point in the history
Because this logic is primarily intended for CDECL.
  • Loading branch information
ksss committed Mar 24, 2022
1 parent 39a3966 commit d274c72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 8 additions & 8 deletions lib/rbs/prototype/rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ def literal_to_type(node)
value_type = types_to_union_type(value_types)
BuiltinNames::Hash.instance_type([key_type, value_type])
end
when :CALL
receiver, method_name, * = node.children
case method_name
when :freeze, :tap, :itself, :dup, :clone, :taint, :untaint, :extend
literal_to_type(receiver)
else
default
end
else
untyped
end
Expand Down Expand Up @@ -597,14 +605,6 @@ def node_type(node, default: Types::Bases::Any.new(location: nil))
BuiltinNames::Array.instance_type(default)
when :HASH
BuiltinNames::Hash.instance_type(default, default)
when :CALL
receiver, method_name, * = node.children
case method_name
when :freeze, :tap, :itself, :dup, :clone, :taint, :untaint, :extend
node_type(receiver)
else
default
end
else
default
end
Expand Down
6 changes: 1 addition & 5 deletions test/rbs/rb_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def self.world
end
def kw_req(a:) end
def opt_with_method_call(a = 'a'.freeze, b: 'b'.dup) end
end
EOR

Expand All @@ -63,8 +61,6 @@ def hello: (untyped a, ?::Integer b, *untyped c, untyped d, e: untyped e, ?f: ::
def self.world: () { (untyped, untyped, untyped, x: untyped, y: untyped) -> untyped } -> untyped
def kw_req: (a: untyped a) -> nil
def opt_with_method_call: (?::String a, ?b: ::String b) -> nil
end
EOF
end
Expand Down Expand Up @@ -576,7 +572,7 @@ module Foo
module Foo
VERSION: "0.1.1"
FROZEN: untyped
FROZEN: "str"
::Hello::World: :foo
end
Expand Down

0 comments on commit d274c72

Please sign in to comment.