Exception: RBS::DuplicatedMethodDefinitionError

Inherits:
DefinitionError show all
Defined in:
lib/rbs/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, method_name:, members:) ⇒ DuplicatedMethodDefinitionError

Returns a new instance of DuplicatedMethodDefinitionError.



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/rbs/errors.rb', line 214

def initialize(type:, method_name:, members:)
  @type = type
  @method_name = method_name
  @members = members

  message = "#{Location.to_string location}: #{qualified_method_name} has duplicated definitions"
  if members.size > 1
    message << " in #{other_locations.map { |loc| Location.to_string loc }.join(', ')}"
  end
  super message
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



212
213
214
# File 'lib/rbs/errors.rb', line 212

def members
  @members
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



211
212
213
# File 'lib/rbs/errors.rb', line 211

def method_name
  @method_name
end

#typeObject (readonly)

Returns the value of attribute type.



210
211
212
# File 'lib/rbs/errors.rb', line 210

def type
  @type
end

Instance Method Details

#locationObject



239
240
241
# File 'lib/rbs/errors.rb', line 239

def location
  members[0].location
end

#other_locationsObject



243
244
245
# File 'lib/rbs/errors.rb', line 243

def other_locations
  members.drop(1).map(&:location)
end

#qualified_method_nameObject



226
227
228
229
230
231
232
233
# File 'lib/rbs/errors.rb', line 226

def qualified_method_name
  case type
  when Types::ClassSingleton
    "#{type.name}.#{method_name}"
  else
    "#{type.name}##{method_name}"
  end
end

#type_nameObject



235
236
237
# File 'lib/rbs/errors.rb', line 235

def type_name
  type.name
end