@@ -669,6 +669,8 @@ def body_type(node)
669669 body_type ( node . statements )
670670 when Prism ::StatementsNode
671671 block_type ( node )
672+ when Prism ::ReturnNode
673+ return_node_to_type ( node )
672674 else
673675 literal_to_type ( node )
674676 end
@@ -678,21 +680,16 @@ def block_type(node)
678680 return_stmts = any_node? ( node ) do |n |
679681 n . is_a? ( Prism ::ReturnNode )
680682 end &.map do |return_node |
681- return_args = return_node . arguments &.arguments || [ ]
682- return_types = return_args . map { |arg | literal_to_type ( arg ) }
683-
684- if return_types . size >= 2
685- t = types_to_union_type ( return_types )
686- BuiltinNames ::Array . instance_type ( t )
687- else
688- return_types . first || Types ::Bases ::Nil . new ( location : nil )
689- end
683+ return_node_to_type ( return_node )
690684 end || [ ]
691685
692686 last_node = node . compact_child_nodes . last
693- last_evaluated = last_node ? literal_to_type ( last_node ) : Types ::Bases ::Nil . new ( location : nil )
694- # FIXME: Skipt if last_evaluated ReturnNode
695- types_to_union_type ( [ *return_stmts , last_evaluated ] )
687+ case last_node
688+ when nil , Prism ::ReturnNode
689+ types_to_union_type ( return_stmts )
690+ else
691+ types_to_union_type ( [ *return_stmts , literal_to_type ( last_node ) ] )
692+ end
696693 end
697694
698695 def literal_to_symbol ( node )
@@ -784,6 +781,18 @@ def literal_to_type(node)
784781 end
785782 end
786783
784+ def return_node_to_type ( node )
785+ return_args = node . arguments &.arguments || [ ]
786+ return_types = return_args . map { |arg | literal_to_type ( arg ) }
787+
788+ if return_types . size >= 2
789+ t = types_to_union_type ( return_types )
790+ BuiltinNames ::Array . instance_type ( t )
791+ else
792+ return_types . first || Types ::Bases ::Nil . new ( location : nil )
793+ end
794+ end
795+
787796 def types_to_union_type ( types )
788797 return untyped if types . empty?
789798
0 commit comments