@@ -42,6 +42,7 @@ def self.build(param_type_annotations, return_type_annotation, node)
4242
4343 splat_annotation = nil #: Annotations::SplatParamTypeAnnotation?
4444 double_splat_annotation = nil #: Annotations::DoubleSplatParamTypeAnnotation?
45+ param_annotations = { } #: Hash[Symbol, Annotations::ParamTypeAnnotation]
4546 unused = [ ] #: Array[Annotations::ParamTypeAnnotation | Annotations::SplatParamTypeAnnotation | Annotations::DoubleSplatParamTypeAnnotation]
4647
4748 param_type_annotations . each do |annot |
@@ -59,7 +60,12 @@ def self.build(param_type_annotations, return_type_annotation, node)
5960 double_splat_annotation = annot
6061 end
6162 when Annotations ::ParamTypeAnnotation
62- unused << annot
63+ name = annot . name_location . source . to_sym
64+ if param_annotations . key? ( name )
65+ unused << annot
66+ else
67+ param_annotations [ name ] = annot
68+ end
6369 end
6470 end
6571
@@ -68,9 +74,8 @@ def self.build(param_type_annotations, return_type_annotation, node)
6874
6975 params . requireds . each do |param |
7076 if param . is_a? ( Prism ::RequiredParameterNode )
71- annotation = unused . find { _1 . name_location . source . to_sym == param . name }
77+ annotation = param_annotations . delete ( param . name )
7278 if annotation
73- unused . delete ( annotation )
7479 doc . required_positionals << annotation
7580 else
7681 doc . required_positionals << param . name
@@ -80,9 +85,8 @@ def self.build(param_type_annotations, return_type_annotation, node)
8085
8186 params . optionals . each do |param |
8287 if param . is_a? ( Prism ::OptionalParameterNode )
83- annotation = unused . find { _1 . name_location . source . to_sym == param . name }
88+ annotation = param_annotations . delete ( param . name )
8489 if annotation
85- unused . delete ( annotation )
8690 doc . optional_positionals << annotation
8791 else
8892 doc . optional_positionals << param . name
@@ -101,9 +105,8 @@ def self.build(param_type_annotations, return_type_annotation, node)
101105
102106 params . posts . each do |param |
103107 if param . is_a? ( Prism ::RequiredParameterNode )
104- annotation = unused . find { _1 . name_location . source . to_sym == param . name }
108+ annotation = param_annotations . delete ( param . name )
105109 if annotation
106- unused . delete ( annotation )
107110 doc . trailing_positionals << annotation
108111 else
109112 doc . trailing_positionals << param . name
@@ -114,17 +117,15 @@ def self.build(param_type_annotations, return_type_annotation, node)
114117 params . keywords . each do |param |
115118 case param
116119 when Prism ::RequiredKeywordParameterNode
117- annotation = unused . find { _1 . name_location . source . to_sym == param . name }
120+ annotation = param_annotations . delete ( param . name )
118121 if annotation
119- unused . delete ( annotation )
120122 doc . required_keywords [ param . name ] = annotation
121123 else
122124 doc . required_keywords [ param . name ] = param . name
123125 end
124126 when Prism ::OptionalKeywordParameterNode
125- annotation = unused . find { _1 . name_location . source . to_sym == param . name }
127+ annotation = param_annotations . delete ( param . name )
126128 if annotation
127- unused . delete ( annotation )
128129 doc . optional_keywords [ param . name ] = annotation
129130 else
130131 doc . optional_keywords [ param . name ] = param . name
@@ -142,6 +143,7 @@ def self.build(param_type_annotations, return_type_annotation, node)
142143 end
143144 end
144145
146+ unused . concat ( param_annotations . values )
145147 unused << splat_annotation if splat_annotation
146148 unused << double_splat_annotation if double_splat_annotation
147149
0 commit comments