Skip to content

Commit e6017cd

Browse files
authored
Fix stale Hash::_Key expectations from upstream RBS core drift (#1224)
* Fix stale Hash::_Key expectations from upstream RBS core drift RBS core's `Hash#[]` now types its key parameter as the `_Key` duck-type interface rather than the generic `K`, so instantiating `Hash{Symbol => untyped}` no longer substitutes `Symbol` for the key param type. The two specs added for #1042 asserted the old `Symbol` value; update them to the now-correct `::Hash::_Key`. * Make Hash::_Key expectation conditional on RBS version CI's rspec matrix pins RBS versions 3.10.0 through 4.0.2, all of which predate the _Key duck-type interface change (introduced in RBS 4.1.0) - only my local environment's latest RBS picked up the new behavior. Make the expectation depend on the installed RBS::VERSION so both old and new RBS are covered correctly, following the existing pattern used elsewhere in this file for RBS-version-gated behavior.
1 parent f75f562 commit e6017cd

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

spec/convention/activesupport_concern_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,17 @@ class Sub < Hash[Symbol, untyped]
187187
end
188188

189189
it 'finds superclass method pin parameter type' do
190+
# RBS core's Hash#[] started taking its key as the _Key duck-type
191+
# interface instead of the generic K as of RBS 4.1.0, so instantiating
192+
# Hash{Symbol => untyped} no longer substitutes the param type on
193+
# newer RBS - see ruby/rbs core/hash.rbs.
194+
expected = if Gem::Version.new(RBS::VERSION) >= Gem::Version.new('4.1.0')
195+
['::Hash::_Key']
196+
else
197+
['Symbol']
198+
end
190199
expect(sup_method_stack.flat_map(&:signatures).flat_map(&:parameters).map(&:return_type).map(&:rooted_tags)
191-
.uniq).to eq(['Symbol'])
200+
.uniq).to eq(expected)
192201
end
193202
end
194203
end

spec/rbs_map/conversions_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,17 @@ class Sub < Hash[Symbol, untyped]
142142
end
143143

144144
it 'finds superclass method pin parameter type' do
145+
# RBS core's Hash#[] started taking its key as the _Key duck-type
146+
# interface instead of the generic K as of RBS 4.1.0, so instantiating
147+
# Hash{Symbol => untyped} no longer substitutes the param type on
148+
# newer RBS - see ruby/rbs core/hash.rbs.
149+
expected = if Gem::Version.new(RBS::VERSION) >= Gem::Version.new('4.1.0')
150+
['::Hash::_Key']
151+
else
152+
['Symbol']
153+
end
145154
expect(sup_method_stack.flat_map(&:signatures).flat_map(&:parameters).map(&:return_type).map(&:rooted_tags)
146-
.uniq).to eq(['Symbol'])
155+
.uniq).to eq(expected)
147156
end
148157
end
149158
end

0 commit comments

Comments
 (0)