diff --git a/lib/rbi/parser.rb b/lib/rbi/parser.rb index 1d311d40..1b9fc180 100644 --- a/lib/rbi/parser.rb +++ b/lib/rbi/parser.rb @@ -240,12 +240,18 @@ def visit_constant_assign(node) sig { override.params(node: Prism::DefNode).void } def visit_def_node(node) @last_node = node + + # We need to collect the comments with `current_sigs_comments` _before_ visiting the parameters to make sure + # the method comments are properly associated with the sigs and not the parameters. + comments = current_sigs_comments + node_comments(node) + params = parse_params(node.parameters) + current_scope << Method.new( node.name.to_s, - params: parse_params(node.parameters), + params: params, sigs: current_sigs, loc: node_loc(node), - comments: current_sigs_comments + node_comments(node), + comments: comments, is_singleton: !!node.receiver, ) @last_node = nil diff --git a/test/rbi/parser_test.rb b/test/rbi/parser_test.rb index a62674f0..f8368a20 100644 --- a/test/rbi/parser_test.rb +++ b/test/rbi/parser_test.rb @@ -720,7 +720,7 @@ module A # B comment class B # c comment - def c; end + def c(a); end # d comment attr_reader :a