{"record":{"id":"4bdbd93e1772f69e","repo":"ruby/ruby","slug":"self-and-other-have-different-names","errorCode":null,"errorMessage":"#{self} and #{other} have different names","messagePattern":"#(.+?) and #(.+?) have different names","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/rubygems/dependency.rb","lineNumber":259,"sourceCode":"  # Does this dependency match +spec+?\n  #\n  # NOTE:  This is not a convenience method.  Unlike #match? this method\n  # returns true when +spec+ is a prerelease version even if this dependency\n  # is not a prerelease dependency.\n\n  def matches_spec?(spec)\n    return false unless name === spec.name\n    return true  if requirement.none?\n\n    requirement.satisfied_by?(spec.version)\n  end\n\n  ##\n  # Merges the requirements of +other+ into this dependency\n\n  def merge(other)\n    unless name == other.name\n      raise ArgumentError,\n            \"#{self} and #{other} have different names\"\n    end\n\n    default = Gem::Requirement.default\n    self_req = requirement\n    other_req = other.requirement\n\n    return self.class.new name, self_req  if other_req == default\n    return self.class.new name, other_req if self_req  == default\n\n    self.class.new name, self_req.as_list.concat(other_req.as_list)\n  end\n\n  def matching_specs(platform_only = false)\n    matches = Gem::Specification.find_all_by_name(name, requirement)\n\n    if platform_only\n      matches.reject! do |spec|","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/ruby/ruby/blob/0e5b888e1c355f3f728f2659f085820937dada48/lib/rubygems/dependency.rb#L241-L277","documentation":"Gem::Dependency#merge unions the requirement lists of two dependencies and is only defined for dependencies on the same gem. Merging dependencies whose names differ raises ArgumentError ('<self> and <other> have different names').","triggerScenarios":"`dep.merge(other)` where dep.name != other.name — resolution/merge code that pairs dependencies positionally or by index instead of by name, or a generic merge helper applied to heterogeneous dependency lists.","commonSituations":"Homegrown resolvers combining two gemfiles/lockfiles; refactors assuming parallel arrays stay aligned; deduplication logic that merges whatever is next in the list.","solutions":["Group dependencies by name (hash keyed by d.name) and merge only matching pairs.","Guard the call site: merge only `if a.name == b.name`, otherwise keep both dependencies.","Fix the upstream pairing logic that produced mismatched couples."],"exampleFix":"# before\nmerged = deps[i].merge(other_deps[i])\n# after\nothers = other_deps.to_h { |d| [d.name, d] }\nmerged = deps.map { |d| others.key?(d.name) ? d.merge(others[d.name]) : d }","handlingStrategy":"validation","validationCode":"raise ArgumentError, \"#{a.name} and #{b.name} differ\" unless a.name == b.name\na.merge(b)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Key dependency collections by name, never by array index.","Assert name equality inside generic merge helpers."],"tags":["rubygems","dependency","merge","argumenterror","conflict"],"backgroundTag":"conflicting-dependency-definitions","analyzedSha":"0e5b888e1c355f3f728f2659f085820937dada48","analyzedAt":"2026-08-21T14:25:43.473Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}