Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/solargraph/complex_type/unique_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def eql? other
# @sg-ignore flow sensitive typing should support .class == .class
@subtypes == other.subtypes &&
# @sg-ignore flow sensitive typing should support .class == .class
@rooted == other.rooted? &&
rooted? == other.rooted? &&
# @sg-ignore flow sensitive typing should support .class == .class
@all_params == other.all_params &&
# @sg-ignore flow sensitive typing should support .class == .class
Expand Down Expand Up @@ -273,7 +273,7 @@ def conforms_to? api_map, expected, situation, rules = [],
end

def hash
[self.class, @name, @key_types, @sub_types, @rooted, @all_params, @parameters_type].hash
[self.class, @name, @key_types, @sub_types, rooted?, @all_params, @parameters_type].hash
end

# @return [self]
Expand Down
22 changes: 22 additions & 0 deletions spec/complex_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -765,4 +765,26 @@ def make_bar
expect(atype.conforms_to?(api_map, ptype, :method_call)).to be(true)
end
end

context 'with Ruby equality of types' do
it 'considers two parses of a name that cannot be rooted equal' do
a = Solargraph::ComplexType.parse('undefined').items.first
b = Solargraph::ComplexType.parse('undefined').items.first
expect(a).to eql(b)
expect(a.hash).to eq(b.hash)
end

it 'treats the rooted flag as meaningless on a name that cannot be rooted' do
unrooted = Solargraph::ComplexType::UniqueType.new('undefined', rooted: false)
rooted = Solargraph::ComplexType::UniqueType.new('undefined', rooted: true)
expect(unrooted).to eql(rooted)
expect(unrooted.hash).to eq(rooted.hash)
end

it 'still distinguishes a name that can be rooted by its rooted flag' do
rooted = Solargraph::ComplexType::UniqueType.new('String', rooted: true)
unrooted = Solargraph::ComplexType::UniqueType.new('String', rooted: false)
expect(rooted).not_to eql(unrooted)
end
end
end
Loading