File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -479,10 +479,12 @@ def merge_with(other)
479479 super
480480
481481 # If self is the all-anonymous side (since compatible_with? ensures
482- # at most one side is), adopt other's non-anonymous param names and sigs.
483- if params . all? ( &:anonymous? )
482+ # at most one side is), or if self has no sigs but other does, adopt
483+ # other's non-anonymous param names and sigs.
484+ if params . all? ( &:anonymous? ) || ( sigs . empty? && !other . sigs . empty? )
484485 @params = other . params . dup
485486 @sigs = other . sigs . dup unless other . sigs . empty?
487+ return
486488 end
487489
488490 other . sigs . each do |sig |
Original file line number Diff line number Diff line change @@ -1333,5 +1333,30 @@ def m2(_a); end
13331333 RBI
13341334 refute_empty ( res . conflicts )
13351335 end
1336+
1337+ def test_merge_methods_without_sig_adopts_params_and_sig_from_other
1338+ tree1 = parse_rbi ( <<~RBI )
1339+ class Foo
1340+ def expand=(value); end
1341+ end
1342+ RBI
1343+
1344+ tree2 = parse_rbi ( <<~RBI )
1345+ class Foo
1346+ sig { params(a_different_name: T.nilable(T::Array[String])).returns(T.nilable(T::Array[String])) }
1347+ def expand=(a_different_name); end
1348+ end
1349+ RBI
1350+
1351+ res = tree1 . merge ( tree2 )
1352+
1353+ assert_equal ( <<~RBI , res . string )
1354+ class Foo
1355+ sig { params(a_different_name: T.nilable(T::Array[String])).returns(T.nilable(T::Array[String])) }
1356+ def expand=(a_different_name); end
1357+ end
1358+ RBI
1359+ assert_empty ( res . conflicts )
1360+ end
13361361 end
13371362end
You can’t perform that action at this time.
0 commit comments