Exception: RBS::DuplicatedMethodDefinitionError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DetailedMessageable

#detailed_message

Constructor Details

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

Returns a new instance of DuplicatedMethodDefinitionError.



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/rbs/errors.rb', line 250

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.



248
249
250
# File 'lib/rbs/errors.rb', line 248

def members
  @members
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



247
248
249
# File 'lib/rbs/errors.rb', line 247

def method_name
  @method_name
end

#typeObject (readonly)

Returns the value of attribute type.



246
247
248
# File 'lib/rbs/errors.rb', line 246

def type
  @type
end

Instance Method Details

#locationObject



275
276
277
# File 'lib/rbs/errors.rb', line 275

def location
  members[0].location
end

#other_locationsObject



279
280
281
# File 'lib/rbs/errors.rb', line 279

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

#qualified_method_nameObject



262
263
264
265
266
267
268
269
# File 'lib/rbs/errors.rb', line 262

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

#type_nameObject



271
272
273
# File 'lib/rbs/errors.rb', line 271

def type_name
  type.name
end